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 ());
182 /* Handle .weak. This is a GNU extension. */
185 obj_coff_weak (ignore)
194 name = input_line_pointer;
195 c = get_symbol_end ();
196 symbolP = symbol_find_or_make (name);
197 *input_line_pointer = c;
201 S_SET_WEAK (symbolP);
205 S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
207 S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT);
212 input_line_pointer++;
214 if (*input_line_pointer == '\n')
220 demand_empty_rest_of_line ();
225 static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *));
227 #define GET_FILENAME_STRING(X) \
228 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
232 fetch_coff_debug_section ()
234 static segT debug_section;
238 s = bfd_make_debug_symbol (stdoutput, (char *) 0, 0);
240 debug_section = s->section;
242 return debug_section;
246 SA_SET_SYM_ENDNDX (sym, val)
250 combined_entry_type *entry, *p;
252 entry = &coffsymbol (sym->bsym)->native[1];
253 p = coffsymbol (val->bsym)->native;
254 entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p;
259 SA_SET_SYM_TAGNDX (sym, val)
263 combined_entry_type *entry, *p;
265 entry = &coffsymbol (sym->bsym)->native[1];
266 p = coffsymbol (val->bsym)->native;
267 entry->u.auxent.x_sym.x_tagndx.p = p;
272 S_GET_DATA_TYPE (sym)
275 return coffsymbol (sym->bsym)->native->u.syment.n_type;
279 S_SET_DATA_TYPE (sym, val)
283 coffsymbol (sym->bsym)->native->u.syment.n_type = val;
288 S_GET_STORAGE_CLASS (sym)
291 return coffsymbol (sym->bsym)->native->u.syment.n_sclass;
295 S_SET_STORAGE_CLASS (sym, val)
299 coffsymbol (sym->bsym)->native->u.syment.n_sclass = val;
303 /* Merge a debug symbol containing debug information into a normal symbol. */
306 c_symbol_merge (debug, normal)
310 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
311 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
313 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
315 /* take the most we have */
316 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
319 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
321 /* Move all the auxiliary information. */
322 memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug),
323 (S_GET_NUMBER_AUXILIARY (debug)
324 * sizeof (*SYM_AUXINFO (debug))));
327 /* Move the debug flags. */
328 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
332 c_dot_file_symbol (filename)
337 symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag);
339 S_SET_STORAGE_CLASS (symbolP, C_FILE);
340 S_SET_NUMBER_AUXILIARY (symbolP, 1);
342 symbolP->bsym->flags = BSF_DEBUGGING;
349 listing_source_file (filename);
354 /* Make sure that the symbol is first on the symbol chain */
355 if (symbol_rootP != symbolP)
357 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
358 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
359 } /* if not first on the list */
362 /* Line number handling */
365 struct line_no *next;
372 /* Symbol of last function, which we should hang line#s off of. */
373 static symbolS *line_fsym;
375 #define in_function() (line_fsym != 0)
376 #define clear_function() (line_fsym = 0)
377 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
381 coff_obj_symbol_new_hook (symbolP)
384 long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
385 char * s = (char *) xmalloc (sz);
388 coffsymbol (symbolP->bsym)->native = (combined_entry_type *) s;
390 S_SET_DATA_TYPE (symbolP, T_NULL);
391 S_SET_STORAGE_CLASS (symbolP, 0);
392 S_SET_NUMBER_AUXILIARY (symbolP, 0);
394 if (S_IS_STRING (symbolP))
395 SF_SET_STRING (symbolP);
397 if (S_IS_LOCAL (symbolP))
398 SF_SET_LOCAL (symbolP);
403 * Handle .ln directives.
406 static symbolS *current_lineno_sym;
407 static struct line_no *line_nos;
408 /* @@ Blindly assume all .ln directives will be in the .text section... */
412 add_lineno (frag, offset, num)
417 struct line_no *new_line =
418 (struct line_no *) xmalloc (sizeof (struct line_no));
419 if (!current_lineno_sym)
423 new_line->next = line_nos;
424 new_line->frag = frag;
425 new_line->l.line_number = num;
426 new_line->l.u.offset = offset;
432 coff_add_linesym (sym)
437 coffsymbol (current_lineno_sym->bsym)->lineno = (alent *) line_nos;
441 current_lineno_sym = sym;
445 obj_coff_ln (appline)
450 if (! appline && def_symbol_in_progress != NULL)
452 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
453 demand_empty_rest_of_line ();
457 l = get_absolute_expression ();
460 add_lineno (frag_now, frag_now_fix (), l);
464 new_logical_line ((char *) NULL, l - 1);
473 l += coff_line_base - 1;
474 listing_source_line (l);
479 demand_empty_rest_of_line ();
485 * Handle .def directives.
487 * One might ask : why can't we symbol_new if the symbol does not
488 * already exist and fill it with debug information. Because of
489 * the C_EFCN special symbol. It would clobber the value of the
490 * function symbol before we have a chance to notice that it is
491 * a C_EFCN. And a second reason is that the code is more clear this
492 * way. (at least I think it is :-).
496 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
497 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
498 *input_line_pointer == '\t') \
499 input_line_pointer++;
505 char name_end; /* Char after the end of name */
506 char *symbol_name; /* Name of the debug symbol */
507 char *symbol_name_copy; /* Temporary copy of the name */
508 unsigned int symbol_name_length;
510 if (def_symbol_in_progress != NULL)
512 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
513 demand_empty_rest_of_line ();
515 } /* if not inside .def/.endef */
519 symbol_name = input_line_pointer;
520 #ifdef STRIP_UNDERSCORE
521 if (symbol_name[0] == '_' && symbol_name[1] != 0)
523 #endif /* STRIP_UNDERSCORE */
525 name_end = get_symbol_end ();
526 symbol_name_length = strlen (symbol_name);
527 symbol_name_copy = xmalloc (symbol_name_length + 1);
528 strcpy (symbol_name_copy, symbol_name);
529 #ifdef tc_canonicalize_symbol_name
530 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
533 /* Initialize the new symbol */
534 def_symbol_in_progress = symbol_make (symbol_name_copy);
535 def_symbol_in_progress->sy_frag = &zero_address_frag;
536 S_SET_VALUE (def_symbol_in_progress, 0);
538 if (S_IS_STRING (def_symbol_in_progress))
539 SF_SET_STRING (def_symbol_in_progress);
541 *input_line_pointer = name_end;
543 demand_empty_rest_of_line ();
546 unsigned int dim_index;
549 obj_coff_endef (ignore)
556 if (def_symbol_in_progress == NULL)
558 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
559 demand_empty_rest_of_line ();
561 } /* if not inside .def/.endef */
563 /* Set the section number according to storage class. */
564 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
569 SF_SET_TAG (def_symbol_in_progress);
570 /* intentional fallthrough */
573 SF_SET_DEBUG (def_symbol_in_progress);
574 S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());
578 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
579 /* intentional fallthrough */
581 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
582 /* intentional fallthrough */
586 S_SET_SEGMENT (def_symbol_in_progress, text_section);
588 name = bfd_asymbol_name (def_symbol_in_progress->bsym);
589 if (name[1] == 'b' && name[2] == 'f')
591 if (! in_function ())
592 as_warn (_("`%s' symbol without preceding function"), name);
593 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
594 /* Will need relocating */
595 SF_SET_PROCESS (def_symbol_in_progress);
603 #endif /* C_AUTOARG */
609 SF_SET_DEBUG (def_symbol_in_progress);
610 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
617 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
627 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
634 as_warn (_("unexpected storage class %d"),
635 S_GET_STORAGE_CLASS (def_symbol_in_progress));
637 } /* switch on storage class */
639 /* Now that we have built a debug symbol, try to find if we should
640 merge with an existing symbol or not. If a symbol is C_EFCN or
641 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
643 /* Two cases for functions. Either debug followed by definition or
644 definition followed by debug. For definition first, we will
645 merge the debug symbol into the definition. For debug first, the
646 lineno entry MUST point to the definition function or else it
647 will point off into space when obj_crawl_symbol_chain() merges
648 the debug symbol into the real symbol. Therefor, let's presume
649 the debug symbol is a real function reference. */
651 /* FIXME-SOON If for some reason the definition label/symbol is
652 never seen, this will probably leave an undefined symbol at link
655 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
656 || (!strcmp (bfd_get_section_name (stdoutput,
657 S_GET_SEGMENT (def_symbol_in_progress)),
659 && !SF_GET_TAG (def_symbol_in_progress))
660 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
661 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL)
663 if (def_symbol_in_progress != symbol_lastP)
664 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
669 /* This symbol already exists, merge the newly created symbol
670 into the old one. This is not mandatory. The linker can
671 handle duplicate symbols correctly. But I guess that it save
672 a *lot* of space if the assembly file defines a lot of
675 /* The debug entry (def_symbol_in_progress) is merged into the
676 previous definition. */
678 c_symbol_merge (def_symbol_in_progress, symbolP);
679 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
681 def_symbol_in_progress = symbolP;
683 if (SF_GET_FUNCTION (def_symbol_in_progress)
684 || SF_GET_TAG (def_symbol_in_progress)
685 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
687 /* For functions, and tags, and static symbols, the symbol
688 *must* be where the debug symbol appears. Move the
689 existing symbol to the current place. */
690 /* If it already is at the end of the symbol list, do nothing */
691 if (def_symbol_in_progress != symbol_lastP)
693 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
694 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);
699 if (SF_GET_TAG (def_symbol_in_progress))
703 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
705 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
706 tag_insert (S_GET_NAME (def_symbol_in_progress),
707 def_symbol_in_progress);
710 if (SF_GET_FUNCTION (def_symbol_in_progress))
712 know (sizeof (def_symbol_in_progress) <= sizeof (long));
713 set_function (def_symbol_in_progress);
714 SF_SET_PROCESS (def_symbol_in_progress);
718 /* That is, if this is the first time we've seen the
720 symbol_table_insert (def_symbol_in_progress);
721 } /* definition follows debug */
722 } /* Create the line number entry pointing to the function being defined */
724 def_symbol_in_progress = NULL;
725 demand_empty_rest_of_line ();
729 obj_coff_dim (ignore)
734 if (def_symbol_in_progress == NULL)
736 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
737 demand_empty_rest_of_line ();
739 } /* if not inside .def/.endef */
741 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
743 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
746 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
747 get_absolute_expression ());
749 switch (*input_line_pointer)
752 input_line_pointer++;
756 as_warn (_("badly formed .dim directive ignored"));
757 /* intentional fallthrough */
765 demand_empty_rest_of_line ();
769 obj_coff_line (ignore)
774 if (def_symbol_in_progress == NULL)
776 /* Probably stabs-style line? */
781 this_base = get_absolute_expression ();
782 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress)))
783 coff_line_base = this_base;
785 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
786 SA_SET_SYM_LNNO (def_symbol_in_progress, coff_line_base);
788 demand_empty_rest_of_line ();
791 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0)
796 listing_source_line ((unsigned int) coff_line_base);
802 obj_coff_size (ignore)
805 if (def_symbol_in_progress == NULL)
807 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
808 demand_empty_rest_of_line ();
810 } /* if not inside .def/.endef */
812 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
813 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
814 demand_empty_rest_of_line ();
818 obj_coff_scl (ignore)
821 if (def_symbol_in_progress == NULL)
823 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
824 demand_empty_rest_of_line ();
826 } /* if not inside .def/.endef */
828 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
829 demand_empty_rest_of_line ();
833 obj_coff_tag (ignore)
839 if (def_symbol_in_progress == NULL)
841 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
842 demand_empty_rest_of_line ();
846 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
847 symbol_name = input_line_pointer;
848 name_end = get_symbol_end ();
850 #ifdef tc_canonicalize_symbol_name
851 symbol_name = tc_canonicalize_symbol_name (symbol_name);
854 /* Assume that the symbol referred to by .tag is always defined.
855 This was a bad assumption. I've added find_or_make. xoxorich. */
856 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
857 tag_find_or_make (symbol_name));
858 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
860 as_warn (_("tag not found for .tag %s"), symbol_name);
863 SF_SET_TAGGED (def_symbol_in_progress);
864 *input_line_pointer = name_end;
866 demand_empty_rest_of_line ();
870 obj_coff_type (ignore)
873 if (def_symbol_in_progress == NULL)
875 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
876 demand_empty_rest_of_line ();
878 } /* if not inside .def/.endef */
880 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
882 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
883 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
885 SF_SET_FUNCTION (def_symbol_in_progress);
886 } /* is a function */
888 demand_empty_rest_of_line ();
892 obj_coff_val (ignore)
895 if (def_symbol_in_progress == NULL)
897 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
898 demand_empty_rest_of_line ();
900 } /* if not inside .def/.endef */
902 if (is_name_beginner (*input_line_pointer))
904 char *symbol_name = input_line_pointer;
905 char name_end = get_symbol_end ();
907 #ifdef tc_canonicalize_symbol_name
908 symbol_name = tc_canonicalize_symbol_name (symbol_name);
910 if (!strcmp (symbol_name, "."))
912 def_symbol_in_progress->sy_frag = frag_now;
913 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
914 /* If the .val is != from the .def (e.g. statics) */
916 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
918 def_symbol_in_progress->sy_value.X_op = O_symbol;
919 def_symbol_in_progress->sy_value.X_add_symbol =
920 symbol_find_or_make (symbol_name);
921 def_symbol_in_progress->sy_value.X_op_symbol = NULL;
922 def_symbol_in_progress->sy_value.X_add_number = 0;
924 /* If the segment is undefined when the forward reference is
925 resolved, then copy the segment id from the forward
927 SF_SET_GET_SEGMENT (def_symbol_in_progress);
929 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
930 *input_line_pointer = name_end;
934 S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
935 } /* if symbol based */
937 demand_empty_rest_of_line ();
941 coff_obj_read_begin_hook ()
943 /* These had better be the same. Usually 18 bytes. */
945 know (sizeof (SYMENT) == sizeof (AUXENT));
946 know (SYMESZ == AUXESZ);
952 symbolS *coff_last_function;
953 static symbolS *coff_last_bf;
956 coff_frob_symbol (symp, punt)
960 static symbolS *last_tagP;
961 static stack *block_stack;
962 static symbolS *set_end;
963 symbolS *next_set_end = NULL;
965 if (symp == &abs_symbol)
971 if (current_lineno_sym)
972 coff_add_linesym ((symbolS *) 0);
975 block_stack = stack_init (512, sizeof (symbolS*));
977 if (S_IS_WEAK (symp))
980 S_SET_STORAGE_CLASS (symp, C_NT_WEAK);
982 S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
986 if (!S_IS_DEFINED (symp)
988 && S_GET_STORAGE_CLASS (symp) != C_STAT)
989 S_SET_STORAGE_CLASS (symp, C_EXT);
991 if (!SF_GET_DEBUG (symp))
994 if (!SF_GET_LOCAL (symp)
995 && !SF_GET_STATICS (symp)
996 && (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
999 c_symbol_merge (symp, real);
1002 if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp))
1004 assert (S_GET_VALUE (symp) == 0);
1005 S_SET_EXTERNAL (symp);
1007 else if (S_GET_STORAGE_CLASS (symp) == C_NULL)
1009 if (S_GET_SEGMENT (symp) == text_section
1010 && symp != seg_info (text_section)->sym)
1011 S_SET_STORAGE_CLASS (symp, C_LABEL);
1013 S_SET_STORAGE_CLASS (symp, C_STAT);
1015 if (SF_GET_PROCESS (symp))
1017 if (S_GET_STORAGE_CLASS (symp) == C_BLOCK)
1019 if (!strcmp (S_GET_NAME (symp), ".bb"))
1020 stack_push (block_stack, (char *) &symp);
1024 begin = *(symbolS **) stack_pop (block_stack);
1026 as_warn (_("mismatched .eb"));
1028 next_set_end = begin;
1031 if (coff_last_function == 0 && SF_GET_FUNCTION (symp))
1033 union internal_auxent *auxp;
1034 coff_last_function = symp;
1035 if (S_GET_NUMBER_AUXILIARY (symp) < 1)
1036 S_SET_NUMBER_AUXILIARY (symp, 1);
1037 auxp = &coffsymbol (symp->bsym)->native[1].u.auxent;
1038 memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0,
1039 sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen));
1041 if (S_GET_STORAGE_CLASS (symp) == C_EFCN)
1043 if (coff_last_function == 0)
1044 as_fatal (_("C_EFCN symbol out of scope"));
1045 SA_SET_SYM_FSIZE (coff_last_function,
1046 (long) (S_GET_VALUE (symp)
1047 - S_GET_VALUE (coff_last_function)));
1048 next_set_end = coff_last_function;
1049 coff_last_function = 0;
1052 if (S_IS_EXTERNAL (symp))
1053 S_SET_STORAGE_CLASS (symp, C_EXT);
1054 else if (SF_GET_LOCAL (symp))
1057 if (SF_GET_FUNCTION (symp))
1058 symp->bsym->flags |= BSF_FUNCTION;
1063 if (SF_GET_TAG (symp))
1065 else if (S_GET_STORAGE_CLASS (symp) == C_EOS)
1066 next_set_end = last_tagP;
1069 /* This is pretty horrible, but we have to set *punt correctly in
1070 order to call SA_SET_SYM_ENDNDX correctly. */
1071 if (! symp->sy_used_in_reloc
1072 && ((symp->bsym->flags & BSF_SECTION_SYM) != 0
1073 || (! S_IS_EXTERNAL (symp)
1074 && ! symp->sy_tc.output
1075 && S_GET_STORAGE_CLASS (symp) != C_FILE)))
1079 if (set_end != (symbolS *) NULL
1081 && ((symp->bsym->flags & BSF_NOT_AT_END) != 0
1082 || (S_IS_DEFINED (symp)
1083 && ! S_IS_COMMON (symp)
1084 && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp)))))
1086 SA_SET_SYM_ENDNDX (set_end, symp);
1090 if (next_set_end != NULL
1092 set_end = next_set_end;
1095 && S_GET_STORAGE_CLASS (symp) == C_FCN
1096 && strcmp (S_GET_NAME (symp), ".bf") == 0)
1098 if (coff_last_bf != NULL)
1099 SA_SET_SYM_ENDNDX (coff_last_bf, symp);
1100 coff_last_bf = symp;
1103 if (coffsymbol (symp->bsym)->lineno)
1106 struct line_no *lptr;
1109 lptr = (struct line_no *) coffsymbol (symp->bsym)->lineno;
1110 for (i = 0; lptr; lptr = lptr->next)
1112 lptr = (struct line_no *) coffsymbol (symp->bsym)->lineno;
1114 /* We need i entries for line numbers, plus 1 for the first
1115 entry which BFD will override, plus 1 for the last zero
1116 entry (a marker for BFD). */
1117 l = (alent *) xmalloc ((i + 2) * sizeof (alent));
1118 coffsymbol (symp->bsym)->lineno = l;
1119 l[i + 1].line_number = 0;
1120 l[i + 1].u.sym = NULL;
1124 lptr->l.u.offset += lptr->frag->fr_address;
1132 coff_adjust_section_syms (abfd, sec, x)
1138 segment_info_type *seginfo = seg_info (sec);
1139 int nlnno, nrelocs = 0;
1141 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1142 tc-ppc.c. Do not get confused by it. */
1143 if (seginfo == NULL)
1146 if (!strcmp (sec->name, ".text"))
1147 nlnno = coff_n_line_nos;
1151 /* @@ Hope that none of the fixups expand to more than one reloc
1153 fixS *fixp = seginfo->fix_root;
1156 if (! fixp->fx_done)
1158 fixp = fixp->fx_next;
1161 if (bfd_get_section_size_before_reloc (sec) == 0
1164 && sec != text_section
1165 && sec != data_section
1166 && sec != bss_section)
1168 secsym = section_symbol (sec);
1169 SA_SET_SCN_NRELOC (secsym, nrelocs);
1170 SA_SET_SCN_NLINNO (secsym, nlnno);
1174 coff_frob_file_after_relocs ()
1176 bfd_map_over_sections (stdoutput, coff_adjust_section_syms, (char*) 0);
1180 * implement the .section pseudo op:
1181 * .section name {, "flags"}
1183 * | +--- optional flags: 'b' for bss
1185 * +-- section name 'l' for lib
1189 * 'd' (apparently m88k for data)
1191 * 'r' for read-only data
1192 * But if the argument is not a quoted string, treat it as a
1193 * subsegment number.
1197 obj_coff_section (ignore)
1200 /* Strip out the section name */
1216 section_name = input_line_pointer;
1217 c = get_symbol_end ();
1219 name = xmalloc (input_line_pointer - section_name + 1);
1220 strcpy (name, section_name);
1222 *input_line_pointer = c;
1227 flags = SEC_NO_FLAGS;
1229 if (*input_line_pointer == ',')
1231 ++input_line_pointer;
1233 if (*input_line_pointer != '"')
1234 exp = get_absolute_expression ();
1237 ++input_line_pointer;
1238 while (*input_line_pointer != '"'
1239 && ! is_end_of_line[(unsigned char) *input_line_pointer])
1241 switch (*input_line_pointer)
1243 case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
1244 case 'n': flags &=~ SEC_LOAD; break;
1246 case 'w': flags &=~ SEC_READONLY; break;
1247 case 'x': flags |= SEC_CODE; break;
1248 case 'r': flags |= SEC_READONLY; break;
1250 case 'i': /* STYP_INFO */
1251 case 'l': /* STYP_LIB */
1252 case 'o': /* STYP_OVER */
1253 as_warn (_("unsupported section attribute '%c'"),
1254 *input_line_pointer);
1258 as_warn(_("unknown section attribute '%c'"),
1259 *input_line_pointer);
1262 ++input_line_pointer;
1264 if (*input_line_pointer == '"')
1265 ++input_line_pointer;
1269 sec = subseg_new (name, (subsegT) exp);
1271 if (flags != SEC_NO_FLAGS)
1275 oldflags = bfd_get_section_flags (stdoutput, sec);
1276 oldflags &= SEC_LINK_ONCE | SEC_LINK_DUPLICATES;
1279 if (! bfd_set_section_flags (stdoutput, sec, flags))
1280 as_warn (_("error setting flags for \"%s\": %s"),
1281 bfd_section_name (stdoutput, sec),
1282 bfd_errmsg (bfd_get_error ()));
1285 demand_empty_rest_of_line ();
1289 coff_adjust_symtab ()
1291 if (symbol_rootP == NULL
1292 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
1293 c_dot_file_symbol ("fake");
1297 coff_frob_section (sec)
1303 bfd_vma size, n_entries, mask;
1305 /* The COFF back end in BFD requires that all section sizes be
1306 rounded up to multiples of the corresponding section alignments.
1307 Seems kinda silly to me, but that's the way it is. */
1308 size = bfd_get_section_size_before_reloc (sec);
1309 mask = ((bfd_vma) 1 << (bfd_vma) sec->alignment_power) - 1;
1312 size = (size + mask) & ~mask;
1313 bfd_set_section_size (stdoutput, sec, size);
1316 /* If the section size is non-zero, the section symbol needs an aux
1317 entry associated with it, indicating the size. We don't know
1318 all the values yet; coff_frob_symbol will fill them in later. */
1320 || sec == text_section
1321 || sec == data_section
1322 || sec == bss_section)
1324 symbolS *secsym = section_symbol (sec);
1326 S_SET_STORAGE_CLASS (secsym, C_STAT);
1327 S_SET_NUMBER_AUXILIARY (secsym, 1);
1328 SF_SET_STATICS (secsym);
1329 SA_SET_SCN_SCNLEN (secsym, size);
1332 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1333 #ifndef STAB_SECTION_NAME
1334 #define STAB_SECTION_NAME ".stab"
1336 #ifndef STAB_STRING_SECTION_NAME
1337 #define STAB_STRING_SECTION_NAME ".stabstr"
1339 if (strcmp (STAB_STRING_SECTION_NAME, sec->name))
1343 sec = subseg_get (STAB_SECTION_NAME, 0);
1344 /* size is already rounded up, since other section will be listed first */
1345 size = bfd_get_section_size_before_reloc (strsec);
1347 n_entries = bfd_get_section_size_before_reloc (sec) / 12 - 1;
1349 /* Find first non-empty frag. It should be large enough. */
1350 fragp = seg_info (sec)->frchainP->frch_root;
1351 while (fragp && fragp->fr_fix == 0)
1352 fragp = fragp->fr_next;
1353 assert (fragp != 0 && fragp->fr_fix >= 12);
1355 /* Store the values. */
1356 p = fragp->fr_literal;
1357 bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6);
1358 bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8);
1362 obj_coff_init_stab_section (seg)
1368 unsigned int stroff;
1370 /* Make space for this first symbol. */
1374 as_where (&file, (unsigned int *) NULL);
1375 stabstr_name = (char *) alloca (strlen (seg->name) + 4);
1376 strcpy (stabstr_name, seg->name);
1377 strcat (stabstr_name, "str");
1378 stroff = get_stab_string_offset (file, stabstr_name);
1380 md_number_to_chars (p, stroff, 4);
1389 return ((s == NULL) ? "(NULL)" : S_GET_NAME (s));
1397 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
1399 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1400 (unsigned long) symbolP,
1401 S_GET_NAME(symbolP),
1402 (long) S_GET_DATA_TYPE(symbolP),
1403 S_GET_STORAGE_CLASS(symbolP),
1404 (int) S_GET_SEGMENT(symbolP));
1410 #else /* not BFD_ASSEMBLER */
1413 /* This is needed because we include internal bfd things. */
1417 #include "libcoff.h"
1420 #include "coff/pe.h"
1423 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1424 that we can stick sections together without causing trouble. */
1426 #define NOP_OPCODE 0x00
1429 /* The zeroes if symbol name is longer than 8 chars */
1430 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1432 #define MIN(a,b) ((a) < (b)? (a) : (b))
1433 /* This vector is used to turn an internal segment into a section #
1434 suitable for insertion into a coff symbol table
1437 const short seg_N_TYPE[] =
1438 { /* in: segT out: N_TYPE bits */
1440 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1441 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1442 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1443 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1444 C_UNDEF_SECTION, /* SEG_UNKNOWN */
1445 C_UNDEF_SECTION, /* SEG_GOOF */
1446 C_UNDEF_SECTION, /* SEG_EXPR */
1447 C_DEBUG_SECTION, /* SEG_DEBUG */
1448 C_NTV_SECTION, /* SEG_NTV */
1449 C_PTV_SECTION, /* SEG_PTV */
1450 C_REGISTER_SECTION, /* SEG_REGISTER */
1453 int function_lineoff = -1; /* Offset in line#s where the last function
1454 started (the odd entry for line #0) */
1456 /* structure used to keep the filenames which
1457 are too long around so that we can stick them
1458 into the string table */
1459 struct filename_list
1462 struct filename_list *next;
1465 static struct filename_list *filename_list_head;
1466 static struct filename_list *filename_list_tail;
1468 static symbolS *last_line_symbol;
1470 /* Add 4 to the real value to get the index and compensate the
1471 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1472 section number into a segment number
1474 static symbolS *previous_file_symbol;
1475 void c_symbol_merge ();
1476 static int line_base;
1478 symbolS *c_section_symbol ();
1481 static void fixup_segment PARAMS ((segment_info_type *segP,
1482 segT this_segment_type));
1485 static void fixup_mdeps PARAMS ((fragS *,
1490 static void fill_section PARAMS ((bfd * abfd,
1495 static int c_line_new PARAMS ((symbolS * symbol, long paddr,
1500 static void w_symbols PARAMS ((bfd * abfd, char *where,
1501 symbolS * symbol_rootP));
1503 static void adjust_stab_section PARAMS ((bfd *abfd, segT seg));
1505 static void obj_coff_lcomm PARAMS ((int));
1506 static void obj_coff_text PARAMS ((int));
1507 static void obj_coff_data PARAMS ((int));
1508 static void obj_coff_ident PARAMS ((int));
1509 void obj_coff_section PARAMS ((int));
1513 We allow more than just the standard 3 sections, infact, we allow
1514 40 sections, (though the usual three have to be there).
1516 This structure performs the mappings for us:
1526 static const seg_info_type seg_info_off_by_4[] =
1533 {SEG_E0}, {SEG_E1}, {SEG_E2}, {SEG_E3}, {SEG_E4},
1534 {SEG_E5}, {SEG_E6}, {SEG_E7}, {SEG_E8}, {SEG_E9},
1535 {SEG_E10},{SEG_E11},{SEG_E12},{SEG_E13},{SEG_E14},
1536 {SEG_E15},{SEG_E16},{SEG_E17},{SEG_E18},{SEG_E19},
1537 {SEG_E20},{SEG_E21},{SEG_E22},{SEG_E23},{SEG_E24},
1538 {SEG_E25},{SEG_E26},{SEG_E27},{SEG_E28},{SEG_E29},
1539 {SEG_E30},{SEG_E31},{SEG_E32},{SEG_E33},{SEG_E34},
1540 {SEG_E35},{SEG_E36},{SEG_E37},{SEG_E38},{SEG_E39},
1555 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1557 static relax_addressT
1558 relax_align (address, alignment)
1559 relax_addressT address;
1562 relax_addressT mask;
1563 relax_addressT new_address;
1565 mask = ~((~0) << alignment);
1566 new_address = (address + mask) & (~mask);
1567 return (new_address - address);
1575 return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum).seg_t;
1578 /* calculate the size of the frag chain and fill in the section header
1579 to contain all of it, also fill in the addr of the sections */
1581 size_section (abfd, idx)
1586 unsigned int size = 0;
1587 fragS *frag = segment_info[idx].frchainP->frch_root;
1590 size = frag->fr_address;
1591 if (frag->fr_address != size)
1593 fprintf (stderr, _("Out of step\n"));
1594 size = frag->fr_address;
1597 switch (frag->fr_type)
1599 #ifdef TC_COFF_SIZEMACHDEP
1600 case rs_machine_dependent:
1601 size += TC_COFF_SIZEMACHDEP (frag);
1605 assert (frag->fr_symbol == 0);
1608 size += frag->fr_fix;
1609 size += frag->fr_offset * frag->fr_var;
1616 size += frag->fr_fix;
1617 off = relax_align (size, frag->fr_offset);
1618 if (frag->fr_subtype != 0 && off > frag->fr_subtype)
1624 BAD_CASE (frag->fr_type);
1627 frag = frag->fr_next;
1629 segment_info[idx].scnhdr.s_size = size;
1635 count_entries_in_chain (idx)
1638 unsigned int nrelocs;
1641 /* Count the relocations */
1642 fixup_ptr = segment_info[idx].fix_root;
1644 while (fixup_ptr != (fixS *) NULL)
1646 if (fixup_ptr->fx_done == 0 && TC_COUNT_RELOC (fixup_ptr))
1649 if (fixup_ptr->fx_r_type == RELOC_CONSTH)
1658 fixup_ptr = fixup_ptr->fx_next;
1665 static int compare_external_relocs PARAMS ((const PTR, const PTR));
1667 /* AUX's ld expects relocations to be sorted */
1669 compare_external_relocs (x, y)
1673 struct external_reloc *a = (struct external_reloc *) x;
1674 struct external_reloc *b = (struct external_reloc *) y;
1675 bfd_vma aadr = bfd_getb32 (a->r_vaddr);
1676 bfd_vma badr = bfd_getb32 (b->r_vaddr);
1677 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
1682 /* output all the relocations for a section */
1684 do_relocs_for (abfd, h, file_cursor)
1687 unsigned long *file_cursor;
1689 unsigned int nrelocs;
1691 unsigned long reloc_start = *file_cursor;
1693 for (idx = SEG_E0; idx < SEG_LAST; idx++)
1695 if (segment_info[idx].scnhdr.s_name[0])
1697 struct external_reloc *ext_ptr;
1698 struct external_reloc *external_reloc_vec;
1699 unsigned int external_reloc_size;
1700 unsigned int base = segment_info[idx].scnhdr.s_paddr;
1701 fixS *fix_ptr = segment_info[idx].fix_root;
1702 nrelocs = count_entries_in_chain (idx);
1705 /* Bypass this stuff if no relocs. This also incidentally
1706 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1708 external_reloc_size = nrelocs * RELSZ;
1709 external_reloc_vec =
1710 (struct external_reloc *) malloc (external_reloc_size);
1712 ext_ptr = external_reloc_vec;
1714 /* Fill in the internal coff style reloc struct from the
1715 internal fix list. */
1718 struct internal_reloc intr;
1720 /* Only output some of the relocations */
1721 if (fix_ptr->fx_done == 0 && TC_COUNT_RELOC (fix_ptr))
1723 #ifdef TC_RELOC_MANGLE
1724 TC_RELOC_MANGLE (&segment_info[idx], fix_ptr, &intr,
1729 symbolS *symbol_ptr = fix_ptr->fx_addsy;
1731 intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr);
1733 base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where;
1735 #ifdef TC_KEEP_FX_OFFSET
1736 intr.r_offset = fix_ptr->fx_offset;
1741 while (symbol_ptr->sy_value.X_op == O_symbol
1742 && (! S_IS_DEFINED (symbol_ptr)
1743 || S_IS_COMMON (symbol_ptr)))
1747 /* We must avoid looping, as that can occur
1748 with a badly written program. */
1749 n = symbol_ptr->sy_value.X_add_symbol;
1750 if (n == symbol_ptr)
1755 /* Turn the segment of the symbol into an offset. */
1758 resolve_symbol_value (symbol_ptr, 1);
1759 if (! symbol_ptr->sy_resolved)
1764 if (expr_symbol_where (symbol_ptr, &file, &line))
1765 as_bad_where (file, line,
1766 _("unresolved relocation"));
1768 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1769 S_GET_NAME (symbol_ptr));
1771 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
1774 intr.r_symndx = dot->sy_number;
1778 intr.r_symndx = symbol_ptr->sy_number;
1788 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
1791 #if defined(TC_A29K)
1793 /* The 29k has a special kludge for the high 16 bit
1794 reloc. Two relocations are emited, R_IHIHALF,
1795 and R_IHCONST. The second one doesn't contain a
1796 symbol, but uses the value for offset. */
1798 if (intr.r_type == R_IHIHALF)
1800 /* now emit the second bit */
1801 intr.r_type = R_IHCONST;
1802 intr.r_symndx = fix_ptr->fx_addnumber;
1803 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
1809 fix_ptr = fix_ptr->fx_next;
1813 /* Sort the reloc table */
1814 qsort ((PTR) external_reloc_vec, nrelocs,
1815 sizeof (struct external_reloc), compare_external_relocs);
1818 /* Write out the reloc table */
1819 bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size,
1821 free (external_reloc_vec);
1823 /* Fill in section header info. */
1824 segment_info[idx].scnhdr.s_relptr = *file_cursor;
1825 *file_cursor += external_reloc_size;
1826 segment_info[idx].scnhdr.s_nreloc = nrelocs;
1831 segment_info[idx].scnhdr.s_relptr = 0;
1835 /* Set relocation_size field in file headers */
1836 H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0);
1840 /* run through a frag chain and write out the data to go with it, fill
1841 in the scnhdrs with the info on the file postions
1844 fill_section (abfd, h, file_cursor)
1847 unsigned long *file_cursor;
1851 unsigned int paddr = 0;
1853 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
1855 unsigned int offset = 0;
1856 struct internal_scnhdr *s = &(segment_info[i].scnhdr);
1862 fragS *frag = segment_info[i].frchainP->frch_root;
1869 buffer = xmalloc (s->s_size);
1870 s->s_scnptr = *file_cursor;
1872 know (s->s_paddr == paddr);
1874 if (strcmp (s->s_name, ".text") == 0)
1875 s->s_flags |= STYP_TEXT;
1876 else if (strcmp (s->s_name, ".data") == 0)
1877 s->s_flags |= STYP_DATA;
1878 else if (strcmp (s->s_name, ".bss") == 0)
1881 s->s_flags |= STYP_BSS;
1883 /* @@ Should make the i386 and a29k coff targets define
1884 COFF_NOLOAD_PROBLEM, and have only one test here. */
1887 #ifndef COFF_NOLOAD_PROBLEM
1888 /* Apparently the SVR3 linker (and exec syscall) and UDI
1889 mondfe progrem are confused by noload sections. */
1890 s->s_flags |= STYP_NOLOAD;
1895 else if (strcmp (s->s_name, ".lit") == 0)
1896 s->s_flags = STYP_LIT | STYP_TEXT;
1897 else if (strcmp (s->s_name, ".init") == 0)
1898 s->s_flags |= STYP_TEXT;
1899 else if (strcmp (s->s_name, ".fini") == 0)
1900 s->s_flags |= STYP_TEXT;
1901 else if (strncmp (s->s_name, ".comment", 8) == 0)
1902 s->s_flags |= STYP_INFO;
1906 unsigned int fill_size;
1907 switch (frag->fr_type)
1909 case rs_machine_dependent:
1912 memcpy (buffer + frag->fr_address,
1914 (unsigned int) frag->fr_fix);
1915 offset += frag->fr_fix;
1920 assert (frag->fr_symbol == 0);
1927 memcpy (buffer + frag->fr_address,
1929 (unsigned int) frag->fr_fix);
1930 offset += frag->fr_fix;
1933 fill_size = frag->fr_var;
1934 if (fill_size && frag->fr_offset > 0)
1937 unsigned int off = frag->fr_fix;
1938 for (count = frag->fr_offset; count; count--)
1940 if (fill_size + frag->fr_address + off <= s->s_size)
1942 memcpy (buffer + frag->fr_address + off,
1943 frag->fr_literal + frag->fr_fix,
1946 offset += fill_size;
1951 case rs_broken_word:
1956 frag = frag->fr_next;
1961 if (s->s_scnptr != 0)
1963 bfd_write (buffer, s->s_size, 1, abfd);
1964 *file_cursor += s->s_size;
1973 /* Coff file generation & utilities */
1976 coff_header_append (abfd, h)
1983 #ifdef COFF_LONG_SECTION_NAMES
1984 unsigned long string_size = 4;
1987 bfd_seek (abfd, 0, 0);
1989 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1990 H_SET_MAGIC_NUMBER (h, COFF_MAGIC);
1991 H_SET_VERSION_STAMP (h, 0);
1992 H_SET_ENTRY_POINT (h, 0);
1993 H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address);
1994 H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address);
1995 H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr,
1997 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1998 H_SET_SIZEOF_OPTIONAL_HEADER (h, 0);
1999 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2001 i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer);
2003 bfd_write (buffer, i, 1, abfd);
2004 bfd_write (buffero, H_GET_SIZEOF_OPTIONAL_HEADER (h), 1, abfd);
2006 for (i = SEG_E0; i < SEG_LAST; i++)
2008 if (segment_info[i].scnhdr.s_name[0])
2012 #ifdef COFF_LONG_SECTION_NAMES
2013 /* Support long section names as found in PE. This code
2014 must coordinate with that in write_object_file and
2016 if (strlen (segment_info[i].name) > SCNNMLEN)
2018 memset (segment_info[i].scnhdr.s_name, 0, SCNNMLEN);
2019 sprintf (segment_info[i].scnhdr.s_name, "/%lu", string_size);
2020 string_size += strlen (segment_info[i].name) + 1;
2024 size = bfd_coff_swap_scnhdr_out (abfd,
2025 &(segment_info[i].scnhdr),
2028 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2029 bfd_write (buffer, size, 1, abfd);
2036 symbol_to_chars (abfd, where, symbolP)
2041 unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
2045 /* Turn any symbols with register attributes into abs symbols */
2046 if (S_GET_SEGMENT (symbolP) == reg_section)
2048 S_SET_SEGMENT (symbolP, absolute_section);
2050 /* At the same time, relocate all symbols to their output value */
2053 val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr
2054 + S_GET_VALUE (symbolP));
2056 val = S_GET_VALUE (symbolP);
2059 S_SET_VALUE (symbolP, val);
2061 symbolP->sy_symbol.ost_entry.n_value = val;
2063 where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry,
2066 for (i = 0; i < numaux; i++)
2068 where += bfd_coff_swap_aux_out (abfd,
2069 &symbolP->sy_symbol.ost_auxent[i],
2070 S_GET_DATA_TYPE (symbolP),
2071 S_GET_STORAGE_CLASS (symbolP),
2079 coff_obj_symbol_new_hook (symbolP)
2082 char underscore = 0; /* Symbol has leading _ */
2084 /* Effective symbol */
2085 /* Store the pointer in the offset. */
2086 S_SET_ZEROES (symbolP, 0L);
2087 S_SET_DATA_TYPE (symbolP, T_NULL);
2088 S_SET_STORAGE_CLASS (symbolP, 0);
2089 S_SET_NUMBER_AUXILIARY (symbolP, 0);
2090 /* Additional information */
2091 symbolP->sy_symbol.ost_flags = 0;
2092 /* Auxiliary entries */
2093 memset ((char *) &symbolP->sy_symbol.ost_auxent[0], 0, AUXESZ);
2095 if (S_IS_STRING (symbolP))
2096 SF_SET_STRING (symbolP);
2097 if (!underscore && S_IS_LOCAL (symbolP))
2098 SF_SET_LOCAL (symbolP);
2102 * Handle .ln directives.
2106 obj_coff_ln (appline)
2111 if (! appline && def_symbol_in_progress != NULL)
2113 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2114 demand_empty_rest_of_line ();
2116 } /* wrong context */
2118 l = get_absolute_expression ();
2119 c_line_new (0, frag_now_fix (), l, frag_now);
2122 new_logical_line ((char *) NULL, l - 1);
2132 listing_source_line ((unsigned int) l);
2137 demand_empty_rest_of_line ();
2143 * Handle .def directives.
2145 * One might ask : why can't we symbol_new if the symbol does not
2146 * already exist and fill it with debug information. Because of
2147 * the C_EFCN special symbol. It would clobber the value of the
2148 * function symbol before we have a chance to notice that it is
2149 * a C_EFCN. And a second reason is that the code is more clear this
2150 * way. (at least I think it is :-).
2154 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2155 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2156 *input_line_pointer == '\t') \
2157 input_line_pointer++;
2163 char name_end; /* Char after the end of name */
2164 char *symbol_name; /* Name of the debug symbol */
2165 char *symbol_name_copy; /* Temporary copy of the name */
2166 unsigned int symbol_name_length;
2168 if (def_symbol_in_progress != NULL)
2170 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2171 demand_empty_rest_of_line ();
2173 } /* if not inside .def/.endef */
2175 SKIP_WHITESPACES ();
2177 def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress));
2178 memset (def_symbol_in_progress, 0, sizeof (*def_symbol_in_progress));
2180 symbol_name = input_line_pointer;
2181 name_end = get_symbol_end ();
2182 symbol_name_length = strlen (symbol_name);
2183 symbol_name_copy = xmalloc (symbol_name_length + 1);
2184 strcpy (symbol_name_copy, symbol_name);
2185 #ifdef tc_canonicalize_symbol_name
2186 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
2189 /* Initialize the new symbol */
2190 #ifdef STRIP_UNDERSCORE
2191 S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_'
2192 ? symbol_name_copy + 1
2193 : symbol_name_copy));
2194 #else /* STRIP_UNDERSCORE */
2195 S_SET_NAME (def_symbol_in_progress, symbol_name_copy);
2196 #endif /* STRIP_UNDERSCORE */
2197 /* free(symbol_name_copy); */
2198 def_symbol_in_progress->sy_name_offset = (unsigned long) ~0;
2199 def_symbol_in_progress->sy_number = ~0;
2200 def_symbol_in_progress->sy_frag = &zero_address_frag;
2201 S_SET_VALUE (def_symbol_in_progress, 0);
2203 if (S_IS_STRING (def_symbol_in_progress))
2204 SF_SET_STRING (def_symbol_in_progress);
2206 *input_line_pointer = name_end;
2208 demand_empty_rest_of_line ();
2211 unsigned int dim_index;
2215 obj_coff_endef (ignore)
2218 symbolS *symbolP = 0;
2221 if (def_symbol_in_progress == NULL)
2223 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2224 demand_empty_rest_of_line ();
2226 } /* if not inside .def/.endef */
2228 /* Set the section number according to storage class. */
2229 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
2234 SF_SET_TAG (def_symbol_in_progress);
2235 /* intentional fallthrough */
2238 SF_SET_DEBUG (def_symbol_in_progress);
2239 S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG);
2243 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
2244 /* intentional fallthrough */
2246 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
2247 /* intentional fallthrough */
2249 S_SET_SEGMENT (def_symbol_in_progress, SEG_E0);
2251 if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0)
2253 if (function_lineoff < 0)
2255 fprintf (stderr, _("`.bf' symbol without preceding function\n"));
2256 } /* missing function symbol */
2257 SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff;
2259 SF_SET_PROCESS (last_line_symbol);
2260 SF_SET_ADJ_LNNOPTR (last_line_symbol);
2261 SF_SET_PROCESS (def_symbol_in_progress);
2262 function_lineoff = -1;
2264 /* Value is always set to . */
2265 def_symbol_in_progress->sy_frag = frag_now;
2266 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2271 #endif /* C_AUTOARG */
2281 SF_SET_DEBUG (def_symbol_in_progress);
2282 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
2292 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2298 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress));
2300 } /* switch on storage class */
2302 /* Now that we have built a debug symbol, try to find if we should
2303 merge with an existing symbol or not. If a symbol is C_EFCN or
2304 absolute_section or untagged SEG_DEBUG it never merges. We also
2305 don't merge labels, which are in a different namespace, nor
2306 symbols which have not yet been defined since they are typically
2307 unique, nor do we merge tags with non-tags. */
2309 /* Two cases for functions. Either debug followed by definition or
2310 definition followed by debug. For definition first, we will
2311 merge the debug symbol into the definition. For debug first, the
2312 lineno entry MUST point to the definition function or else it
2313 will point off into space when crawl_symbols() merges the debug
2314 symbol into the real symbol. Therefor, let's presume the debug
2315 symbol is a real function reference. */
2317 /* FIXME-SOON If for some reason the definition label/symbol is
2318 never seen, this will probably leave an undefined symbol at link
2321 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
2322 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
2323 || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG
2324 && !SF_GET_TAG (def_symbol_in_progress))
2325 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
2326 || def_symbol_in_progress->sy_value.X_op != O_constant
2327 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL
2328 || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)))
2330 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
2335 /* This symbol already exists, merge the newly created symbol
2336 into the old one. This is not mandatory. The linker can
2337 handle duplicate symbols correctly. But I guess that it save
2338 a *lot* of space if the assembly file defines a lot of
2341 /* The debug entry (def_symbol_in_progress) is merged into the
2342 previous definition. */
2344 c_symbol_merge (def_symbol_in_progress, symbolP);
2345 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2346 def_symbol_in_progress = symbolP;
2348 if (SF_GET_FUNCTION (def_symbol_in_progress)
2349 || SF_GET_TAG (def_symbol_in_progress)
2350 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
2352 /* For functions, and tags, and static symbols, the symbol
2353 *must* be where the debug symbol appears. Move the
2354 existing symbol to the current place. */
2355 /* If it already is at the end of the symbol list, do nothing */
2356 if (def_symbol_in_progress != symbol_lastP)
2358 symbol_remove (def_symbol_in_progress, &symbol_rootP,
2360 symbol_append (def_symbol_in_progress, symbol_lastP,
2361 &symbol_rootP, &symbol_lastP);
2362 } /* if not already in place */
2364 } /* normal or mergable */
2366 if (SF_GET_TAG (def_symbol_in_progress))
2370 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
2372 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
2373 tag_insert (S_GET_NAME (def_symbol_in_progress),
2374 def_symbol_in_progress);
2377 if (SF_GET_FUNCTION (def_symbol_in_progress))
2379 know (sizeof (def_symbol_in_progress) <= sizeof (long));
2381 = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag);
2383 SF_SET_PROCESS (def_symbol_in_progress);
2385 if (symbolP == NULL)
2387 /* That is, if this is the first time we've seen the
2389 symbol_table_insert (def_symbol_in_progress);
2390 } /* definition follows debug */
2391 } /* Create the line number entry pointing to the function being defined */
2393 def_symbol_in_progress = NULL;
2394 demand_empty_rest_of_line ();
2398 obj_coff_dim (ignore)
2403 if (def_symbol_in_progress == NULL)
2405 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2406 demand_empty_rest_of_line ();
2408 } /* if not inside .def/.endef */
2410 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2412 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
2414 SKIP_WHITESPACES ();
2415 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
2416 get_absolute_expression ());
2418 switch (*input_line_pointer)
2421 input_line_pointer++;
2425 as_warn (_("badly formed .dim directive ignored"));
2426 /* intentional fallthrough */
2434 demand_empty_rest_of_line ();
2438 obj_coff_line (ignore)
2444 if (def_symbol_in_progress == NULL)
2450 name = S_GET_NAME (def_symbol_in_progress);
2451 this_base = get_absolute_expression ();
2453 /* Only .bf symbols indicate the use of a new base line number; the
2454 line numbers associated with .ef, .bb, .eb are relative to the
2455 start of the containing function. */
2456 if (!strcmp (".bf", name))
2458 #if 0 /* XXX Can we ever have line numbers going backwards? */
2459 if (this_base > line_base)
2462 line_base = this_base;
2470 listing_source_line ((unsigned int) line_base);
2476 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2477 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
2479 demand_empty_rest_of_line ();
2483 obj_coff_size (ignore)
2486 if (def_symbol_in_progress == NULL)
2488 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2489 demand_empty_rest_of_line ();
2491 } /* if not inside .def/.endef */
2493 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2494 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
2495 demand_empty_rest_of_line ();
2499 obj_coff_scl (ignore)
2502 if (def_symbol_in_progress == NULL)
2504 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2505 demand_empty_rest_of_line ();
2507 } /* if not inside .def/.endef */
2509 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
2510 demand_empty_rest_of_line ();
2514 obj_coff_tag (ignore)
2520 if (def_symbol_in_progress == NULL)
2522 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2523 demand_empty_rest_of_line ();
2527 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2528 symbol_name = input_line_pointer;
2529 name_end = get_symbol_end ();
2530 #ifdef tc_canonicalize_symbol_name
2531 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2534 /* Assume that the symbol referred to by .tag is always defined.
2535 This was a bad assumption. I've added find_or_make. xoxorich. */
2536 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
2537 (long) tag_find_or_make (symbol_name));
2538 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
2540 as_warn (_("tag not found for .tag %s"), symbol_name);
2543 SF_SET_TAGGED (def_symbol_in_progress);
2544 *input_line_pointer = name_end;
2546 demand_empty_rest_of_line ();
2550 obj_coff_type (ignore)
2553 if (def_symbol_in_progress == NULL)
2555 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2556 demand_empty_rest_of_line ();
2558 } /* if not inside .def/.endef */
2560 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
2562 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
2563 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
2565 SF_SET_FUNCTION (def_symbol_in_progress);
2566 } /* is a function */
2568 demand_empty_rest_of_line ();
2572 obj_coff_val (ignore)
2575 if (def_symbol_in_progress == NULL)
2577 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2578 demand_empty_rest_of_line ();
2580 } /* if not inside .def/.endef */
2582 if (is_name_beginner (*input_line_pointer))
2584 char *symbol_name = input_line_pointer;
2585 char name_end = get_symbol_end ();
2587 #ifdef tc_canonicalize_symbol_name
2588 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2591 if (!strcmp (symbol_name, "."))
2593 def_symbol_in_progress->sy_frag = frag_now;
2594 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2595 /* If the .val is != from the .def (e.g. statics) */
2597 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
2599 def_symbol_in_progress->sy_value.X_op = O_symbol;
2600 def_symbol_in_progress->sy_value.X_add_symbol =
2601 symbol_find_or_make (symbol_name);
2602 def_symbol_in_progress->sy_value.X_op_symbol = NULL;
2603 def_symbol_in_progress->sy_value.X_add_number = 0;
2605 /* If the segment is undefined when the forward reference is
2606 resolved, then copy the segment id from the forward
2608 SF_SET_GET_SEGMENT (def_symbol_in_progress);
2610 /* FIXME: gcc can generate address expressions
2611 here in unusual cases (search for "obscure"
2612 in sdbout.c). We just ignore the offset
2613 here, thus generating incorrect debugging
2614 information. We ignore the rest of the
2617 /* Otherwise, it is the name of a non debug symbol and
2618 its value will be calculated later. */
2619 *input_line_pointer = name_end;
2621 /* FIXME: this is to avoid an error message in the
2622 FIXME case mentioned just above. */
2623 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2624 ++input_line_pointer;
2628 S_SET_VALUE (def_symbol_in_progress,
2629 (valueT) get_absolute_expression ());
2630 } /* if symbol based */
2632 demand_empty_rest_of_line ();
2637 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2638 read.c, which then calls this object file format specific routine. */
2641 obj_coff_pe_handle_link_once (type)
2642 enum linkonce_type type;
2644 seg_info (now_seg)->scnhdr.s_flags |= IMAGE_SCN_LNK_COMDAT;
2646 /* We store the type in the seg_info structure, and use it to set up
2647 the auxiliary entry for the section symbol in c_section_symbol. */
2648 seg_info (now_seg)->linkonce = type;
2654 coff_obj_read_begin_hook ()
2656 /* These had better be the same. Usually 18 bytes. */
2658 know (sizeof (SYMENT) == sizeof (AUXENT));
2659 know (SYMESZ == AUXESZ);
2664 /* This function runs through the symbol table and puts all the
2665 externals onto another chain */
2667 /* The chain of globals. */
2668 symbolS *symbol_globalP;
2669 symbolS *symbol_global_lastP;
2671 /* The chain of externals */
2672 symbolS *symbol_externP;
2673 symbolS *symbol_extern_lastP;
2676 symbolS *last_functionP;
2677 static symbolS *last_bfP;
2684 unsigned int symbol_number = 0;
2685 unsigned int last_file_symno = 0;
2687 struct filename_list *filename_list_scan = filename_list_head;
2689 for (symbolP = symbol_rootP;
2691 symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP)
2693 if (symbolP->sy_mri_common)
2695 if (S_GET_STORAGE_CLASS (symbolP) == C_EXT
2697 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
2699 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)
2700 as_bad (_("%s: global symbols not supported in common sections"),
2701 S_GET_NAME (symbolP));
2702 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2706 if (!SF_GET_DEBUG (symbolP))
2708 /* Debug symbols do not need all this rubbish */
2709 symbolS *real_symbolP;
2711 /* L* and C_EFCN symbols never merge. */
2712 if (!SF_GET_LOCAL (symbolP)
2713 && !SF_GET_STATICS (symbolP)
2714 && S_GET_STORAGE_CLASS (symbolP) != C_LABEL
2715 && symbolP->sy_value.X_op == O_constant
2716 && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP))
2717 && real_symbolP != symbolP)
2719 /* FIXME-SOON: where do dups come from?
2720 Maybe tag references before definitions? xoxorich. */
2721 /* Move the debug data from the debug symbol to the
2722 real symbol. Do NOT do the oposite (i.e. move from
2723 real symbol to debug symbol and remove real symbol from the
2724 list.) Because some pointers refer to the real symbol
2725 whereas no pointers refer to the debug symbol. */
2726 c_symbol_merge (symbolP, real_symbolP);
2727 /* Replace the current symbol by the real one */
2728 /* The symbols will never be the last or the first
2729 because : 1st symbol is .file and 3 last symbols are
2730 .text, .data, .bss */
2731 symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP);
2732 symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP);
2733 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2734 symbolP = real_symbolP;
2735 } /* if not local but dup'd */
2737 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_E1))
2739 S_SET_SEGMENT (symbolP, SEG_E0);
2740 } /* push data into text */
2742 resolve_symbol_value (symbolP, 1);
2744 if (S_GET_STORAGE_CLASS (symbolP) == C_NULL)
2746 if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP))
2748 S_SET_EXTERNAL (symbolP);
2750 else if (S_GET_SEGMENT (symbolP) == SEG_E0)
2752 S_SET_STORAGE_CLASS (symbolP, C_LABEL);
2756 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2760 /* Mainly to speed up if not -g */
2761 if (SF_GET_PROCESS (symbolP))
2763 /* Handle the nested blocks auxiliary info. */
2764 if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK)
2766 if (!strcmp (S_GET_NAME (symbolP), ".bb"))
2767 stack_push (block_stack, (char *) &symbolP);
2770 register symbolS *begin_symbolP;
2771 begin_symbolP = *(symbolS **) stack_pop (block_stack);
2772 if (begin_symbolP == (symbolS *) 0)
2773 as_warn (_("mismatched .eb"));
2775 SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2);
2778 /* If we are able to identify the type of a function, and we
2779 are out of a function (last_functionP == 0) then, the
2780 function symbol will be associated with an auxiliary
2782 if (last_functionP == (symbolS *) 0 &&
2783 SF_GET_FUNCTION (symbolP))
2785 last_functionP = symbolP;
2787 if (S_GET_NUMBER_AUXILIARY (symbolP) < 1)
2789 S_SET_NUMBER_AUXILIARY (symbolP, 1);
2790 } /* make it at least 1 */
2792 /* Clobber possible stale .dim information. */
2794 /* Iffed out by steve - this fries the lnnoptr info too */
2795 bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen,
2796 sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen));
2799 if (S_GET_STORAGE_CLASS (symbolP) == C_FCN)
2801 if (strcmp (S_GET_NAME (symbolP), ".bf") == 0)
2803 if (last_bfP != NULL)
2804 SA_SET_SYM_ENDNDX (last_bfP, symbol_number);
2808 else if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN)
2810 /* I don't even know if this is needed for sdb. But
2811 the standard assembler generates it, so... */
2812 if (last_functionP == (symbolS *) 0)
2813 as_fatal (_("C_EFCN symbol out of scope"));
2814 SA_SET_SYM_FSIZE (last_functionP,
2815 (long) (S_GET_VALUE (symbolP) -
2816 S_GET_VALUE (last_functionP)));
2817 SA_SET_SYM_ENDNDX (last_functionP, symbol_number);
2818 last_functionP = (symbolS *) 0;
2822 else if (SF_GET_TAG (symbolP))
2824 /* First descriptor of a structure must point to
2825 the first slot after the structure description. */
2826 last_tagP = symbolP;
2829 else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS)
2831 /* +2 take in account the current symbol */
2832 SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2);
2834 else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE)
2836 /* If the filename was too long to fit in the
2837 auxent, put it in the string table */
2838 if (SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
2839 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
2841 SA_SET_FILE_FNAME_OFFSET (symbolP, string_byte_count);
2842 string_byte_count += strlen (filename_list_scan->filename) + 1;
2843 filename_list_scan = filename_list_scan->next;
2845 if (S_GET_VALUE (symbolP))
2847 S_SET_VALUE (symbolP, last_file_symno);
2848 last_file_symno = symbol_number;
2849 } /* no one points at the first .file symbol */
2850 } /* if debug or tag or eos or file */
2852 #ifdef tc_frob_coff_symbol
2853 tc_frob_coff_symbol (symbolP);
2856 /* We must put the external symbols apart. The loader
2857 does not bomb if we do not. But the references in
2858 the endndx field for a .bb symbol are not corrected
2859 if an external symbol is removed between .bb and .be.
2860 I.e in the following case :
2861 [20] .bb endndx = 22
2864 ld will move the symbol 21 to the end of the list but
2865 endndx will still be 22 instead of 21. */
2868 if (SF_GET_LOCAL (symbolP))
2870 /* remove C_EFCN and LOCAL (L...) symbols */
2871 /* next pointer remains valid */
2872 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2875 else if (symbolP->sy_value.X_op == O_symbol
2876 && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
2878 /* Skip symbols which were equated to undefined or common
2880 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2882 else if (!S_IS_DEFINED (symbolP)
2883 && !S_IS_DEBUG (symbolP)
2884 && !SF_GET_STATICS (symbolP)
2885 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
2887 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
2889 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT))
2891 /* if external, Remove from the list */
2892 symbolS *hold = symbol_previous (symbolP);
2894 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2895 symbol_clear_list_pointers (symbolP);
2896 symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP);
2899 else if (! S_IS_DEBUG (symbolP)
2900 && ! SF_GET_STATICS (symbolP)
2901 && ! SF_GET_FUNCTION (symbolP)
2902 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
2904 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
2906 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK))
2908 symbolS *hold = symbol_previous (symbolP);
2910 /* The O'Reilly COFF book says that defined global symbols
2911 come at the end of the symbol table, just before
2912 undefined global symbols. */
2914 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2915 symbol_clear_list_pointers (symbolP);
2916 symbol_append (symbolP, symbol_global_lastP, &symbol_globalP,
2917 &symbol_global_lastP);
2922 if (SF_GET_STRING (symbolP))
2924 symbolP->sy_name_offset = string_byte_count;
2925 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
2929 symbolP->sy_name_offset = 0;
2930 } /* fix "long" names */
2932 symbolP->sy_number = symbol_number;
2933 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
2934 } /* if local symbol */
2935 } /* traverse the symbol list */
2936 return symbol_number;
2942 glue_symbols (head, tail)
2946 unsigned int symbol_number = 0;
2948 while (*head != NULL)
2950 symbolS *tmp = *head;
2953 symbol_remove (tmp, head, tail);
2954 symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP);
2957 if (SF_GET_STRING (tmp))
2959 tmp->sy_name_offset = string_byte_count;
2960 string_byte_count += strlen (S_GET_NAME (tmp)) + 1;
2964 tmp->sy_name_offset = 0;
2965 } /* fix "long" names */
2967 tmp->sy_number = symbol_number;
2968 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp);
2969 } /* append the entire extern chain */
2971 return symbol_number;
2977 unsigned int symbol_number = 0;
2980 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
2982 symbolP->sy_number = symbol_number;
2984 if (SF_GET_TAGGED (symbolP))
2988 ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number);
2991 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
2994 return symbol_number;
2998 crawl_symbols (h, abfd)
3004 /* Initialize the stack used to keep track of the matching .bb .be */
3006 block_stack = stack_init (512, sizeof (symbolS *));
3008 /* The symbol list should be ordered according to the following sequence
3011 * . debug entries for functions
3012 * . fake symbols for the sections, including .text .data and .bss
3014 * . undefined symbols
3015 * But this is not mandatory. The only important point is to put the
3016 * undefined symbols at the end of the list.
3019 /* Is there a .file symbol ? If not insert one at the beginning. */
3020 if (symbol_rootP == NULL
3021 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
3023 c_dot_file_symbol ("fake");
3027 * Build up static symbols for the sections, they are filled in later
3031 for (i = SEG_E0; i < SEG_LAST; i++)
3032 if (segment_info[i].scnhdr.s_name[0])
3033 segment_info[i].dot = c_section_symbol (segment_info[i].name,
3036 /* Take all the externals out and put them into another chain */
3037 H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ());
3038 /* Take the externals and glue them onto the end.*/
3039 H_SET_SYMBOL_TABLE_SIZE (h,
3040 (H_GET_SYMBOL_COUNT (h)
3041 + glue_symbols (&symbol_globalP,
3042 &symbol_global_lastP)
3043 + glue_symbols (&symbol_externP,
3044 &symbol_extern_lastP)));
3046 H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ());
3047 know (symbol_globalP == NULL);
3048 know (symbol_global_lastP == NULL);
3049 know (symbol_externP == NULL);
3050 know (symbol_extern_lastP == NULL);
3054 * Find strings by crawling along symbol table chain.
3062 struct filename_list *filename_list_scan = filename_list_head;
3064 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3065 md_number_to_chars (where, (valueT) string_byte_count, 4);
3068 #ifdef COFF_LONG_SECTION_NAMES
3069 /* Support long section names as found in PE. This code must
3070 coordinate with that in coff_header_append and write_object_file. */
3074 for (i = SEG_E0; i < SEG_LAST; i++)
3076 if (segment_info[i].scnhdr.s_name[0]
3077 && strlen (segment_info[i].name) > SCNNMLEN)
3081 size = strlen (segment_info[i].name) + 1;
3082 memcpy (where, segment_info[i].name, size);
3087 #endif /* COFF_LONG_SECTION_NAMES */
3089 for (symbolP = symbol_rootP;
3091 symbolP = symbol_next (symbolP))
3095 if (SF_GET_STRING (symbolP))
3097 size = strlen (S_GET_NAME (symbolP)) + 1;
3098 memcpy (where, S_GET_NAME (symbolP), size);
3101 if (S_GET_STORAGE_CLASS (symbolP) == C_FILE
3102 && SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3103 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3105 size = strlen (filename_list_scan->filename) + 1;
3106 memcpy (where, filename_list_scan->filename, size);
3107 filename_list_scan = filename_list_scan ->next;
3114 do_linenos_for (abfd, h, file_cursor)
3117 unsigned long *file_cursor;
3120 unsigned long start = *file_cursor;
3122 for (idx = SEG_E0; idx < SEG_LAST; idx++)
3124 segment_info_type *s = segment_info + idx;
3127 if (s->scnhdr.s_nlnno != 0)
3129 struct lineno_list *line_ptr;
3131 struct external_lineno *buffer =
3132 (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ);
3134 struct external_lineno *dst = buffer;
3136 /* Run through the table we've built and turn it into its external
3137 form, take this chance to remove duplicates */
3139 for (line_ptr = s->lineno_list_head;
3140 line_ptr != (struct lineno_list *) NULL;
3141 line_ptr = line_ptr->next)
3144 if (line_ptr->line.l_lnno == 0)
3146 /* Turn a pointer to a symbol into the symbols' index */
3147 line_ptr->line.l_addr.l_symndx =
3148 ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number;
3152 line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address;
3156 (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst);
3161 s->scnhdr.s_lnnoptr = *file_cursor;
3163 bfd_write (buffer, 1, s->scnhdr.s_nlnno * LINESZ, abfd);
3166 *file_cursor += s->scnhdr.s_nlnno * LINESZ;
3169 H_SET_LINENO_SIZE (h, *file_cursor - start);
3173 /* Now we run through the list of frag chains in a segment and
3174 make all the subsegment frags appear at the end of the
3175 list, as if the seg 0 was extra long */
3182 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3184 frchainS *head = segment_info[i].frchainP;
3186 fragS *prev_frag = &dummy;
3188 while (head && head->frch_seg == i)
3190 prev_frag->fr_next = head->frch_root;
3191 prev_frag = head->frch_last;
3192 head = head->frch_next;
3194 prev_frag->fr_next = 0;
3198 unsigned long machine;
3201 write_object_file ()
3205 struct frchain *frchain_ptr;
3207 object_headers headers;
3208 unsigned long file_cursor;
3211 abfd = bfd_openw (out_file_name, TARGET_FORMAT);
3216 as_perror (_("FATAL: Can't create %s"), out_file_name);
3217 exit (EXIT_FAILURE);
3219 bfd_set_format (abfd, bfd_object);
3220 bfd_set_arch_mach (abfd, BFD_ARCH, machine);
3222 string_byte_count = 4;
3224 for (frchain_ptr = frchain_root;
3225 frchain_ptr != (struct frchain *) NULL;
3226 frchain_ptr = frchain_ptr->frch_next)
3228 /* Run through all the sub-segments and align them up. Also
3229 close any open frags. We tack a .fill onto the end of the
3230 frag chain so that any .align's size can be worked by looking
3231 at the next frag. */
3233 subseg_set (frchain_ptr->frch_seg, frchain_ptr->frch_subseg);
3234 #ifndef SUB_SEGMENT_ALIGN
3235 #define SUB_SEGMENT_ALIGN(SEG) 1
3238 md_do_align (SUB_SEGMENT_ALIGN (now_seg), (char *) NULL, 0, 0,
3241 frag_align (SUB_SEGMENT_ALIGN (now_seg), NOP_OPCODE, 0);
3245 frag_wane (frag_now);
3246 frag_now->fr_fix = 0;
3247 know (frag_now->fr_next == NULL);
3254 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3256 relax_segment (segment_info[i].frchainP->frch_root, i);
3259 H_SET_NUMBER_OF_SECTIONS (&headers, 0);
3261 /* Find out how big the sections are, and set the addresses. */
3263 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3267 segment_info[i].scnhdr.s_paddr = addr;
3268 segment_info[i].scnhdr.s_vaddr = addr;
3270 if (segment_info[i].scnhdr.s_name[0])
3272 H_SET_NUMBER_OF_SECTIONS (&headers,
3273 H_GET_NUMBER_OF_SECTIONS (&headers) + 1);
3275 #ifdef COFF_LONG_SECTION_NAMES
3276 /* Support long section names as found in PE. This code
3277 must coordinate with that in coff_header_append and
3282 len = strlen (segment_info[i].name);
3284 string_byte_count += len + 1;
3286 #endif /* COFF_LONG_SECTION_NAMES */
3289 size = size_section (abfd, (unsigned int) i);
3292 /* I think the section alignment is only used on the i960; the
3293 i960 needs it, and it should do no harm on other targets. */
3294 #ifdef ALIGNMENT_IN_S_FLAGS
3295 segment_info[i].scnhdr.s_flags |= (section_alignment[i] & 0xF) << 8;
3297 segment_info[i].scnhdr.s_align = 1 << section_alignment[i];
3301 H_SET_TEXT_SIZE (&headers, size);
3302 else if (i == SEG_E1)
3303 H_SET_DATA_SIZE (&headers, size);
3304 else if (i == SEG_E2)
3305 H_SET_BSS_SIZE (&headers, size);
3308 /* Turn the gas native symbol table shape into a coff symbol table */
3309 crawl_symbols (&headers, abfd);
3311 if (string_byte_count == 4)
3312 string_byte_count = 0;
3314 H_SET_STRING_SIZE (&headers, string_byte_count);
3320 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3322 fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i);
3323 fixup_segment (&segment_info[i], i);
3326 /* Look for ".stab" segments and fill in their initial symbols
3328 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3330 name = segment_info[i].name;
3333 && strncmp (".stab", name, 5) == 0
3334 && strncmp (".stabstr", name, 8) != 0)
3335 adjust_stab_section (abfd, i);
3338 file_cursor = H_GET_TEXT_FILE_OFFSET (&headers);
3340 bfd_seek (abfd, (file_ptr) file_cursor, 0);
3342 /* Plant the data */
3344 fill_section (abfd, &headers, &file_cursor);
3346 do_relocs_for (abfd, &headers, &file_cursor);
3348 do_linenos_for (abfd, &headers, &file_cursor);
3350 H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC);
3351 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3352 H_SET_TIME_STAMP (&headers, (long)time((time_t *)0));
3354 H_SET_TIME_STAMP (&headers, 0);
3356 #ifdef TC_COFF_SET_MACHINE
3357 TC_COFF_SET_MACHINE (&headers);
3361 #define COFF_FLAGS 0
3364 #ifdef KEEP_RELOC_INFO
3365 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3366 COFF_FLAGS | coff_flags));
3368 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3369 (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) |
3370 COFF_FLAGS | coff_flags));
3374 unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers);
3375 char *buffer1 = xmalloc (symtable_size + string_byte_count + 1);
3377 H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd));
3378 w_symbols (abfd, buffer1, symbol_rootP);
3379 if (string_byte_count > 0)
3380 w_strings (buffer1 + symtable_size);
3381 bfd_write (buffer1, 1, symtable_size + string_byte_count, abfd);
3385 coff_header_append (abfd, &headers);
3387 /* Recent changes to write need this, but where it should
3388 go is up to Ken.. */
3389 if (bfd_close_all_done (abfd) == false)
3390 as_fatal (_("Can't close %s: %s"), out_file_name,
3391 bfd_errmsg (bfd_get_error ()));
3394 extern bfd *stdoutput;
3401 /* Add a new segment. This is called from subseg_new via the
3402 obj_new_segment macro. */
3405 obj_coff_add_segment (name)
3410 #ifndef COFF_LONG_SECTION_NAMES
3411 char buf[SCNNMLEN + 1];
3413 strncpy (buf, name, SCNNMLEN);
3414 buf[SCNNMLEN] = '\0';
3418 for (i = SEG_E0; i < SEG_LAST && segment_info[i].scnhdr.s_name[0]; i++)
3419 if (strcmp (name, segment_info[i].name) == 0)
3424 as_bad (_("Too many new sections; can't add \"%s\""), name);
3428 /* Add a new section. */
3429 strncpy (segment_info[i].scnhdr.s_name, name,
3430 sizeof (segment_info[i].scnhdr.s_name));
3431 segment_info[i].scnhdr.s_flags = STYP_REG;
3432 segment_info[i].name = xstrdup (name);
3438 * implement the .section pseudo op:
3439 * .section name {, "flags"}
3441 * | +--- optional flags: 'b' for bss
3443 * +-- section name 'l' for lib
3447 * 'd' (apparently m88k for data)
3449 * 'r' for read-only data
3450 * But if the argument is not a quoted string, treat it as a
3451 * subsegment number.
3455 obj_coff_section (ignore)
3458 /* Strip out the section name */
3459 char *section_name, *name;
3472 else if (type == 'D')
3474 segment_info[now_seg].scnhdr.s_flags |= flags;
3479 section_name = input_line_pointer;
3480 c = get_symbol_end ();
3482 name = xmalloc (input_line_pointer - section_name + 1);
3483 strcpy (name, section_name);
3485 *input_line_pointer = c;
3491 if (*input_line_pointer == ',')
3493 ++input_line_pointer;
3496 if (*input_line_pointer != '"')
3497 exp = get_absolute_expression ();
3500 ++input_line_pointer;
3501 while (*input_line_pointer != '"'
3502 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3504 switch (*input_line_pointer)
3506 case 'b': flags |= STYP_BSS; break;
3507 case 'i': flags |= STYP_INFO; break;
3508 case 'l': flags |= STYP_LIB; break;
3509 case 'n': flags |= STYP_NOLOAD; break;
3510 case 'o': flags |= STYP_OVER; break;
3512 case 'w': flags |= STYP_DATA; break;
3513 case 'x': flags |= STYP_TEXT; break;
3514 case 'r': flags |= STYP_LIT; break;
3516 as_warn(_("unknown section attribute '%c'"),
3517 *input_line_pointer);
3520 ++input_line_pointer;
3522 if (*input_line_pointer == '"')
3523 ++input_line_pointer;
3527 subseg_new (name, (subsegT) exp);
3529 segment_info[now_seg].scnhdr.s_flags |= flags;
3531 demand_empty_rest_of_line ();
3536 obj_coff_text (ignore)
3539 subseg_new (".text", get_absolute_expression ());
3544 obj_coff_data (ignore)
3547 if (flag_readonly_data_in_text)
3548 subseg_new (".text", get_absolute_expression () + 1000);
3550 subseg_new (".data", get_absolute_expression ());
3554 obj_coff_ident (ignore)
3557 segT current_seg = now_seg; /* save current seg */
3558 subsegT current_subseg = now_subseg;
3559 subseg_new (".comment", 0); /* .comment seg */
3560 stringer (1); /* read string */
3561 subseg_set (current_seg, current_subseg); /* restore current seg */
3565 c_symbol_merge (debug, normal)
3569 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
3570 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
3572 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
3574 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
3575 } /* take the most we have */
3577 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
3579 memcpy ((char *) &normal->sy_symbol.ost_auxent[0],
3580 (char *) &debug->sy_symbol.ost_auxent[0],
3581 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug) * AUXESZ));
3582 } /* Move all the auxiliary information */
3584 /* Move the debug flags. */
3585 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
3586 } /* c_symbol_merge() */
3589 c_line_new (symbol, paddr, line_number, frag)
3595 struct lineno_list *new_line =
3596 (struct lineno_list *) xmalloc (sizeof (struct lineno_list));
3598 segment_info_type *s = segment_info + now_seg;
3599 new_line->line.l_lnno = line_number;
3601 if (line_number == 0)
3603 last_line_symbol = symbol;
3604 new_line->line.l_addr.l_symndx = (long) symbol;
3608 new_line->line.l_addr.l_paddr = paddr;
3611 new_line->frag = (char *) frag;
3612 new_line->next = (struct lineno_list *) NULL;
3615 if (s->lineno_list_head == (struct lineno_list *) NULL)
3617 s->lineno_list_head = new_line;
3621 s->lineno_list_tail->next = new_line;
3623 s->lineno_list_tail = new_line;
3624 return LINESZ * s->scnhdr.s_nlnno++;
3628 c_dot_file_symbol (filename)
3633 symbolP = symbol_new (".file",
3636 &zero_address_frag);
3638 S_SET_STORAGE_CLASS (symbolP, C_FILE);
3639 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3641 if (strlen (filename) > FILNMLEN)
3643 /* Filename is too long to fit into an auxent,
3644 we stick it into the string table instead. We keep
3645 a linked list of the filenames we find so we can emit
3647 struct filename_list *f = ((struct filename_list *)
3648 xmalloc (sizeof (struct filename_list)));
3650 f->filename = filename;
3653 SA_SET_FILE_FNAME_ZEROS (symbolP, 0);
3654 SA_SET_FILE_FNAME_OFFSET (symbolP, 1);
3656 if (filename_list_tail)
3657 filename_list_tail->next = f;
3659 filename_list_head = f;
3660 filename_list_tail = f;
3664 SA_SET_FILE_FNAME (symbolP, filename);
3671 listing_source_file (filename);
3677 SF_SET_DEBUG (symbolP);
3678 S_SET_VALUE (symbolP, (valueT) previous_file_symbol);
3680 previous_file_symbol = symbolP;
3682 /* Make sure that the symbol is first on the symbol chain */
3683 if (symbol_rootP != symbolP)
3685 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3686 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
3688 } /* c_dot_file_symbol() */
3691 * Build a 'section static' symbol.
3695 c_section_symbol (name, idx)
3701 symbolP = symbol_find_base (name, DO_NOT_STRIP);
3702 if (symbolP == NULL)
3703 symbolP = symbol_new (name, idx, 0, &zero_address_frag);
3706 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3707 S_SET_SEGMENT (symbolP, idx);
3708 symbolP->sy_frag = &zero_address_frag;
3711 S_SET_STORAGE_CLASS (symbolP, C_STAT);
3712 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3714 SF_SET_STATICS (symbolP);
3718 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3719 SF_CLEAR_LOCAL (symbolP);
3722 /* If the .linkonce pseudo-op was used for this section, we must
3723 store the information in the auxiliary entry for the section
3725 if (segment_info[idx].linkonce != LINKONCE_UNSET)
3729 switch (segment_info[idx].linkonce)
3733 case LINKONCE_DISCARD:
3734 type = IMAGE_COMDAT_SELECT_ANY;
3736 case LINKONCE_ONE_ONLY:
3737 type = IMAGE_COMDAT_SELECT_NODUPLICATES;
3739 case LINKONCE_SAME_SIZE:
3740 type = IMAGE_COMDAT_SELECT_SAME_SIZE;
3742 case LINKONCE_SAME_CONTENTS:
3743 type = IMAGE_COMDAT_SELECT_EXACT_MATCH;
3747 SYM_AUXENT (symbolP)->x_scn.x_comdat = type;
3752 } /* c_section_symbol() */
3755 w_symbols (abfd, where, symbol_rootP)
3758 symbolS * symbol_rootP;
3763 /* First fill in those values we have only just worked out */
3764 for (i = SEG_E0; i < SEG_LAST; i++)
3766 symbolP = segment_info[i].dot;
3769 SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size);
3770 SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc);
3771 SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno);
3776 * Emit all symbols left in the symbol chain.
3778 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
3780 /* Used to save the offset of the name. It is used to point
3781 to the string in memory but must be a file offset. */
3782 register char *temp;
3784 /* We can't fix the lnnoptr field in yank_symbols with the other
3785 adjustments, because we have to wait until we know where they
3787 if (SF_GET_ADJ_LNNOPTR (symbolP))
3789 SA_GET_SYM_LNNOPTR (symbolP) +=
3790 segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_lnnoptr;
3793 tc_coff_symbol_emit_hook (symbolP);
3795 temp = S_GET_NAME (symbolP);
3796 if (SF_GET_STRING (symbolP))
3798 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
3799 S_SET_ZEROES (symbolP, 0);
3803 memset (symbolP->sy_symbol.ost_entry.n_name, 0, SYMNMLEN);
3804 strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
3806 where = symbol_to_chars (abfd, where, symbolP);
3807 S_SET_NAME (symbolP, temp);
3813 obj_coff_lcomm (ignore)
3826 name = input_line_pointer;
3828 c = get_symbol_end ();
3829 p = input_line_pointer;
3832 if (*input_line_pointer != ',')
3834 as_bad (_("Expected comma after name"));
3835 ignore_rest_of_line ();
3838 if (*input_line_pointer == '\n')
3840 as_bad (_("Missing size expression"));
3843 input_line_pointer++;
3844 if ((temp = get_absolute_expression ()) < 0)
3846 as_warn (_("lcomm length (%d.) <0! Ignored."), temp);
3847 ignore_rest_of_line ();
3852 symbolP = symbol_find_or_make(name);
3854 if (S_GET_SEGMENT(symbolP) == SEG_UNKNOWN &&
3855 S_GET_VALUE(symbolP) == 0)
3860 segT current_seg = now_seg; /* save current seg */
3861 subsegT current_subseg = now_subseg;
3863 subseg_set (SEG_E2, 1);
3864 symbolP->sy_frag = frag_now;
3865 p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP,
3866 (offsetT) temp, (char *) 0);
3868 subseg_set (current_seg, current_subseg); /* restore current seg */
3869 S_SET_SEGMENT(symbolP, SEG_E2);
3870 S_SET_STORAGE_CLASS(symbolP, C_STAT);
3874 as_bad(_("Symbol %s already defined"), name);
3876 demand_empty_rest_of_line();
3881 fixup_mdeps (frags, h, this_segment)
3886 subseg_change (this_segment, 0);
3889 switch (frags->fr_type)
3895 HANDLE_ALIGN (frags);
3897 frags->fr_type = rs_fill;
3899 ((frags->fr_next->fr_address - frags->fr_address - frags->fr_fix)
3902 case rs_machine_dependent:
3903 md_convert_frag (h, this_segment, frags);
3909 frags = frags->fr_next;
3915 #ifndef TC_FORCE_RELOCATION
3916 #define TC_FORCE_RELOCATION(fix) 0
3920 fixup_segment (segP, this_segment_type)
3921 segment_info_type * segP;
3922 segT this_segment_type;
3924 register fixS * fixP;
3925 register symbolS *add_symbolP;
3926 register symbolS *sub_symbolP;
3929 register char *place;
3930 register long where;
3931 register char pcrel;
3932 register fragS *fragP;
3933 register segT add_symbol_segment = absolute_section;
3935 for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next)
3937 fragP = fixP->fx_frag;
3939 where = fixP->fx_where;
3940 place = fragP->fr_literal + where;
3941 size = fixP->fx_size;
3942 add_symbolP = fixP->fx_addsy;
3943 sub_symbolP = fixP->fx_subsy;
3944 add_number = fixP->fx_offset;
3945 pcrel = fixP->fx_pcrel;
3947 /* We want function-relative stabs to work on systems which
3948 may use a relaxing linker; thus we must handle the sym1-sym2
3949 fixups function-relative stabs generates.
3951 Of course, if you actually enable relaxing in the linker, the
3952 line and block scoping information is going to be incorrect
3953 in some cases. The only way to really fix this is to support
3954 a reloc involving the difference of two symbols. */
3956 && (!sub_symbolP || pcrel))
3960 if (fixP->fx_tcbit && SF_GET_CALLNAME (add_symbolP))
3962 /* Relocation should be done via the associated 'bal' entry
3965 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP)))
3967 as_bad_where (fixP->fx_file, fixP->fx_line,
3968 _("No 'bal' entry point for leafproc %s"),
3969 S_GET_NAME (add_symbolP));
3972 fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
3976 /* Make sure the symbols have been resolved; this may not have
3977 happened if these are expression symbols. */
3978 if (add_symbolP != NULL && ! add_symbolP->sy_resolved)
3979 resolve_symbol_value (add_symbolP, 1);
3981 if (add_symbolP != NULL)
3983 /* If this fixup is against a symbol which has been equated
3984 to another symbol, convert it to the other symbol. */
3985 if (add_symbolP->sy_value.X_op == O_symbol
3986 && (! S_IS_DEFINED (add_symbolP)
3987 || S_IS_COMMON (add_symbolP)))
3989 while (add_symbolP->sy_value.X_op == O_symbol
3990 && (! S_IS_DEFINED (add_symbolP)
3991 || S_IS_COMMON (add_symbolP)))
3995 /* We must avoid looping, as that can occur with a
3996 badly written program. */
3997 n = add_symbolP->sy_value.X_add_symbol;
3998 if (n == add_symbolP)
4000 add_number += add_symbolP->sy_value.X_add_number;
4003 fixP->fx_addsy = add_symbolP;
4004 fixP->fx_offset = add_number;
4008 if (sub_symbolP != NULL && ! sub_symbolP->sy_resolved)
4009 resolve_symbol_value (sub_symbolP, 1);
4011 if (add_symbolP != NULL
4012 && add_symbolP->sy_mri_common)
4014 know (add_symbolP->sy_value.X_op == O_symbol);
4015 add_number += S_GET_VALUE (add_symbolP);
4016 fixP->fx_offset = add_number;
4017 add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol;
4022 add_symbol_segment = S_GET_SEGMENT (add_symbolP);
4023 } /* if there is an addend */
4027 if (add_symbolP == NULL || add_symbol_segment == absolute_section)
4029 if (add_symbolP != NULL)
4031 add_number += S_GET_VALUE (add_symbolP);
4033 fixP->fx_addsy = NULL;
4036 /* It's just -sym. */
4037 if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
4039 add_number -= S_GET_VALUE (sub_symbolP);
4046 as_bad_where (fixP->fx_file, fixP->fx_line,
4047 _("Negative of non-absolute symbol %s"),
4048 S_GET_NAME (sub_symbolP));
4050 add_number -= S_GET_VALUE (sub_symbolP);
4051 } /* not absolute */
4053 /* if sub_symbol is in the same segment that add_symbol
4054 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4056 else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
4057 && SEG_NORMAL (add_symbol_segment))
4059 /* Difference of 2 symbols from same segment. Can't
4060 make difference of 2 undefineds: 'value' means
4061 something different for N_UNDF. */
4063 /* Makes no sense to use the difference of 2 arbitrary symbols
4064 as the target of a call instruction. */
4067 as_bad_where (fixP->fx_file, fixP->fx_line,
4068 _("callj to difference of 2 symbols"));
4070 #endif /* TC_I960 */
4071 add_number += S_GET_VALUE (add_symbolP) -
4072 S_GET_VALUE (sub_symbolP);
4075 if (!TC_FORCE_RELOCATION (fixP))
4077 fixP->fx_addsy = NULL;
4078 fixP->fx_subsy = NULL;
4080 #ifdef TC_M68K /* is this right? */
4088 /* Different segments in subtraction. */
4089 know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
4091 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
4093 add_number -= S_GET_VALUE (sub_symbolP);
4096 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
4097 #if 0 /* Okay for 68k, at least... */
4102 /* Make it pc-relative. */
4103 add_number += (md_pcrel_from (fixP)
4104 - S_GET_VALUE (sub_symbolP));
4113 as_bad_where (fixP->fx_file, fixP->fx_line,
4114 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4115 segment_name (S_GET_SEGMENT (sub_symbolP)),
4116 S_GET_NAME (sub_symbolP),
4117 (long) (fragP->fr_address + where));
4120 } /* if sub_symbolP */
4124 if (add_symbol_segment == this_segment_type && pcrel)
4127 * This fixup was made when the symbol's segment was
4128 * SEG_UNKNOWN, but it is now in the local segment.
4129 * So we know how to do the address without relocation.
4132 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4133 * in which cases it modifies *fixP as appropriate. In the case
4134 * of a 'calls', no further work is required, and *fixP has been
4135 * set up to make the rest of the code below a no-op.
4138 #endif /* TC_I960 */
4140 add_number += S_GET_VALUE (add_symbolP);
4141 add_number -= md_pcrel_from (fixP);
4144 add_number -= segP->scnhdr.s_vaddr;
4145 if defined (TC_I386) || defined (TE_LYNX). I now
4146 think that was an error propagated from the case when
4147 we are going to emit the relocation. If we are not
4148 going to emit the relocation, then we just want to
4149 set add_number to the difference between the symbols.
4150 This is a case that would only arise when there is a
4151 PC relative reference from a section other than .text
4152 to a symbol defined in the same section, and the
4153 reference is not relaxed. Since jump instructions on
4154 the i386 are relaxed, this could only arise with a
4155 call instruction. */
4157 pcrel = 0; /* Lie. Don't want further pcrel processing. */
4158 if (!TC_FORCE_RELOCATION (fixP))
4160 fixP->fx_addsy = NULL;
4166 switch (add_symbol_segment)
4168 case absolute_section:
4170 reloc_callj (fixP); /* See comment about reloc_callj() above*/
4171 #endif /* TC_I960 */
4172 add_number += S_GET_VALUE (add_symbolP);
4175 if (!TC_FORCE_RELOCATION (fixP))
4177 fixP->fx_addsy = NULL;
4184 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4185 /* This really should be handled in the linker, but
4186 backward compatibility forbids. */
4187 add_number += S_GET_VALUE (add_symbolP);
4189 add_number += S_GET_VALUE (add_symbolP) +
4190 segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr;
4196 if ((int) fixP->fx_bit_fixP == 13)
4198 /* This is a COBR instruction. They have only a
4199 * 13-bit displacement and are only to be used
4200 * for local branches: flag as error, don't generate
4203 as_bad_where (fixP->fx_file, fixP->fx_line,
4204 _("can't use COBR format with external label"));
4205 fixP->fx_addsy = NULL;
4209 #endif /* TC_I960 */
4210 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4211 /* 386 COFF uses a peculiar format in which the
4212 value of a common symbol is stored in the .text
4213 segment (I've checked this on SVR3.2 and SCO
4215 /* This is also true for 68k COFF on sysv machines
4216 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4217 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4219 if (S_IS_COMMON (add_symbolP))
4220 add_number += S_GET_VALUE (add_symbolP);
4225 } /* switch on symbol seg */
4226 } /* if not in local seg */
4227 } /* if there was a + symbol */
4231 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4232 /* This adjustment is not correct on the m88k, for which the
4233 linker does all the computation. */
4234 add_number -= md_pcrel_from (fixP);
4236 if (add_symbolP == 0)
4238 fixP->fx_addsy = &abs_symbol;
4239 } /* if there's an add_symbol */
4240 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4241 /* On the 386 we must adjust by the segment vaddr as well.
4244 I changed the i960 to work this way as well. This is
4245 compatible with the current GNU linker behaviour. I do
4246 not know what other i960 COFF assemblers do. This is not
4247 a common case: normally, only assembler code will contain
4248 a PC relative reloc, and only branches which do not
4249 originate in the .text section will have a non-zero
4252 I changed the m68k to work this way as well. This will
4253 break existing PC relative relocs from sections which do
4254 not start at address 0, but it will make ld -r work.
4255 Ian Taylor, 4 Oct 96. */
4257 add_number -= segP->scnhdr.s_vaddr;
4261 if (!fixP->fx_bit_fixP && ! fixP->fx_no_overflow)
4264 /* The m88k uses the offset field of the reloc to get around
4267 && ((add_number & ~0xFF)
4268 || (fixP->fx_signed && (add_number & 0x80)))
4269 && ((add_number & ~0xFF) != (-1 & ~0xFF)
4270 || (add_number & 0x80) == 0))
4272 && ((add_number & ~0xFFFF)
4273 || (fixP->fx_signed && (add_number & 0x8000)))
4274 && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF)
4275 || (add_number & 0x8000) == 0)))
4277 as_bad_where (fixP->fx_file, fixP->fx_line,
4278 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4279 (long) add_number, size,
4280 (unsigned long) (fragP->fr_address + where));
4283 #ifdef WARN_SIGNED_OVERFLOW_WORD
4284 /* Warn if a .word value is too large when treated as a
4285 signed number. We already know it is not too negative.
4286 This is to catch over-large switches generated by gcc on
4288 if (!flag_signed_overflow_ok
4290 && add_number > 0x7fff)
4291 as_bad_where (fixP->fx_file, fixP->fx_line,
4292 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4294 (unsigned long) (fragP->fr_address + where));
4296 } /* not a bit fix */
4297 /* Once this fix has been applied, we don't have to output
4298 anything nothing more need be done. */
4299 #ifdef MD_APPLY_FIX3
4300 md_apply_fix3 (fixP, (valueT *) &add_number, this_segment_type);
4302 md_apply_fix (fixP, add_number);
4304 } /* For each fixS in this segment. */
4305 } /* fixup_segment() */
4309 /* The first entry in a .stab section is special. */
4312 obj_coff_init_stab_section (seg)
4318 unsigned int stroff;
4320 /* Make space for this first symbol. */
4324 as_where (&file, (unsigned int *) NULL);
4325 stabstr_name = (char *) alloca (strlen (segment_info[seg].name) + 4);
4326 strcpy (stabstr_name, segment_info[seg].name);
4327 strcat (stabstr_name, "str");
4328 stroff = get_stab_string_offset (file, stabstr_name);
4330 md_number_to_chars (p, stroff, 4);
4333 /* Fill in the counts in the first entry in a .stab section. */
4336 adjust_stab_section(abfd, seg)
4340 segT stabstrseg = SEG_UNKNOWN;
4341 const char *secname, *name2;
4344 int i, strsz = 0, nsyms;
4345 fragS *frag = segment_info[seg].frchainP->frch_root;
4347 /* Look for the associated string table section. */
4349 secname = segment_info[seg].name;
4350 name = (char *) alloca (strlen (secname) + 4);
4351 strcpy (name, secname);
4352 strcat (name, "str");
4354 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
4356 name2 = segment_info[i].name;
4357 if (name2 != NULL && strncmp(name2, name, 8) == 0)
4364 /* If we found the section, get its size. */
4365 if (stabstrseg != SEG_UNKNOWN)
4366 strsz = size_section (abfd, stabstrseg);
4368 nsyms = size_section (abfd, seg) / 12 - 1;
4370 /* Look for the first frag of sufficient size for the initial stab
4371 symbol, and collect a pointer to it. */
4372 while (frag && frag->fr_fix < 12)
4373 frag = frag->fr_next;
4375 p = frag->fr_literal;
4378 /* Write in the number of stab symbols and the size of the string
4380 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
4381 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
4384 #endif /* not BFD_ASSEMBLER */
4386 const pseudo_typeS obj_pseudo_table[] =
4388 {"def", obj_coff_def, 0},
4389 {"dim", obj_coff_dim, 0},
4390 {"endef", obj_coff_endef, 0},
4391 {"line", obj_coff_line, 0},
4392 {"ln", obj_coff_ln, 0},
4393 {"appline", obj_coff_ln, 1},
4394 {"scl", obj_coff_scl, 0},
4395 {"size", obj_coff_size, 0},
4396 {"tag", obj_coff_tag, 0},
4397 {"type", obj_coff_type, 0},
4398 {"val", obj_coff_val, 0},
4399 {"section", obj_coff_section, 0},
4400 {"sect", obj_coff_section, 0},
4401 /* FIXME: We ignore the MRI short attribute. */
4402 {"section.s", obj_coff_section, 0},
4403 {"sect.s", obj_coff_section, 0},
4404 /* We accept the .bss directive for backward compatibility with
4405 earlier versions of gas. */
4406 {"bss", obj_coff_bss, 0},
4407 {"weak", obj_coff_weak, 0},
4408 #ifndef BFD_ASSEMBLER
4409 {"use", obj_coff_section, 0},
4410 {"text", obj_coff_text, 0},
4411 {"data", obj_coff_data, 0},
4412 {"lcomm", obj_coff_lcomm, 0},
4413 {"ident", obj_coff_ident, 0},
4415 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
4416 {"ident", s_ignore, 0}, /* we don't yet handle this. */
4418 {"version", s_ignore, 0},
4419 {"ABORT", s_abort, 0},
4421 /* The m88k uses sdef instead of def. */
4422 {"sdef", obj_coff_def, 0},
4424 {NULL} /* end sentinel */
4425 }; /* obj_pseudo_table */
4427 #ifdef BFD_ASSEMBLER
4429 /* Support for a COFF emulation. */
4434 pop_insert (obj_pseudo_table);
4438 coff_sec_sym_ok_for_reloc (sec)
4450 const struct format_ops coff_format_ops =
4452 bfd_target_coff_flavour,
4457 coff_frob_file_after_relocs,
4462 obj_generate_asm_lineno,
4471 coff_sec_sym_ok_for_reloc,
4478 coff_obj_read_begin_hook,
4479 coff_obj_symbol_new_hook,