1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define OBJ_HEADER "obj-coff.h"
33 /* I think this is probably always correct. */
34 #ifndef KEEP_RELOC_INFO
35 #define KEEP_RELOC_INFO
38 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
39 a new section's attributes when a directive has no valid flags or the
40 "w" flag is used. This default should be appropriate for most. */
41 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
42 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
45 /* This is used to hold the symbol built by a sequence of pseudo-ops
46 from .def and .endef. */
47 static symbolS *def_symbol_in_progress;
49 /* PE weak alternate symbols begin with this string. */
50 static const char weak_altprefix[] = ".weak.";
55 unsigned long chunk_size;
56 unsigned long element_size;
59 unsigned long pointer;
63 static stack *stack_init PARAMS ((unsigned long, unsigned long));
64 static char *stack_push PARAMS ((stack *, char *));
65 static char *stack_pop PARAMS ((stack *));
66 static void tag_init PARAMS ((void));
67 static void tag_insert PARAMS ((const char *, symbolS *));
68 static symbolS *tag_find PARAMS ((char *));
69 static symbolS *tag_find_or_make PARAMS ((char *));
70 static void obj_coff_bss PARAMS ((int));
72 static void obj_coff_weak PARAMS ((int));
74 const char *s_get_name PARAMS ((symbolS * s));
75 static void obj_coff_ln PARAMS ((int));
76 static void obj_coff_def PARAMS ((int));
77 static void obj_coff_endef PARAMS ((int));
78 static void obj_coff_dim PARAMS ((int));
79 static void obj_coff_line PARAMS ((int));
80 static void obj_coff_size PARAMS ((int));
81 static void obj_coff_scl PARAMS ((int));
82 static void obj_coff_tag PARAMS ((int));
83 static void obj_coff_val PARAMS ((int));
84 static void obj_coff_type PARAMS ((int));
85 static void obj_coff_ident PARAMS ((int));
87 static void obj_coff_loc PARAMS((int));
93 stack_init (chunk_size, element_size)
94 unsigned long chunk_size;
95 unsigned long element_size;
99 st = (stack *) malloc (sizeof (stack));
102 st->data = malloc (chunk_size);
109 st->size = chunk_size;
110 st->chunk_size = chunk_size;
111 st->element_size = element_size;
116 /* Not currently used. */
127 stack_push (st, element)
131 if (st->pointer + st->element_size >= st->size)
133 st->size += st->chunk_size;
134 if ((st->data = xrealloc (st->data, st->size)) == (char *) 0)
137 memcpy (st->data + st->pointer, element, st->element_size);
138 st->pointer += st->element_size;
139 return st->data + st->pointer;
146 if (st->pointer < st->element_size)
151 st->pointer -= st->element_size;
152 return st->data + st->pointer;
156 * Maintain a list of the tagnames of the structures.
159 static struct hash_control *tag_hash;
164 tag_hash = hash_new ();
168 tag_insert (name, symbolP)
172 const char *error_string;
174 if ((error_string = hash_jam (tag_hash, name, (char *) symbolP)))
176 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
185 #ifdef STRIP_UNDERSCORE
188 #endif /* STRIP_UNDERSCORE */
189 return (symbolS *) hash_find (tag_hash, name);
193 tag_find_or_make (name)
198 if ((symbolP = tag_find (name)) == NULL)
200 symbolP = symbol_new (name, undefined_section,
201 0, &zero_address_frag);
203 tag_insert (S_GET_NAME (symbolP), symbolP);
205 symbol_table_insert (symbolP);
212 /* We accept the .bss directive to set the section for backward
213 compatibility with earlier versions of gas. */
216 obj_coff_bss (ignore)
217 int ignore ATTRIBUTE_UNUSED;
219 if (*input_line_pointer == '\n')
220 subseg_new (".bss", get_absolute_expression ());
227 static segT fetch_coff_debug_section PARAMS ((void));
228 static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *));
229 static int S_GET_DATA_TYPE PARAMS ((symbolS *));
230 void c_symbol_merge PARAMS ((symbolS *, symbolS *));
231 static void add_lineno PARAMS ((fragS *, addressT, int));
233 #define GET_FILENAME_STRING(X) \
234 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
238 fetch_coff_debug_section ()
240 static segT debug_section;
244 s = bfd_make_debug_symbol (stdoutput, (char *) 0, 0);
246 debug_section = s->section;
248 return debug_section;
252 SA_SET_SYM_ENDNDX (sym, val)
256 combined_entry_type *entry, *p;
258 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
259 p = coffsymbol (symbol_get_bfdsym (val))->native;
260 entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p;
265 SA_SET_SYM_TAGNDX (sym, val)
269 combined_entry_type *entry, *p;
271 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
272 p = coffsymbol (symbol_get_bfdsym (val))->native;
273 entry->u.auxent.x_sym.x_tagndx.p = p;
278 S_GET_DATA_TYPE (sym)
281 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type;
285 S_SET_DATA_TYPE (sym, val)
289 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type = val;
294 S_GET_STORAGE_CLASS (sym)
297 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass;
301 S_SET_STORAGE_CLASS (sym, val)
305 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass = val;
309 /* Merge a debug symbol containing debug information into a normal symbol. */
312 c_symbol_merge (debug, normal)
316 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
317 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
319 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
321 /* take the most we have */
322 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
325 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
327 /* Move all the auxiliary information. */
328 memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug),
329 (S_GET_NUMBER_AUXILIARY (debug)
330 * sizeof (*SYM_AUXINFO (debug))));
333 /* Move the debug flags. */
334 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
338 c_dot_file_symbol (const char *filename, int appfile ATTRIBUTE_UNUSED)
342 /* BFD converts filename to a .file symbol with an aux entry. It
343 also handles chaining. */
344 symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag);
346 S_SET_STORAGE_CLASS (symbolP, C_FILE);
347 S_SET_NUMBER_AUXILIARY (symbolP, 1);
349 symbol_get_bfdsym (symbolP)->flags = BSF_DEBUGGING;
356 listing_source_file (filename);
361 /* Make sure that the symbol is first on the symbol chain */
362 if (symbol_rootP != symbolP)
364 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
365 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
366 } /* if not first on the list */
369 /* Line number handling */
372 struct line_no *next;
379 /* Symbol of last function, which we should hang line#s off of. */
380 static symbolS *line_fsym;
382 #define in_function() (line_fsym != 0)
383 #define clear_function() (line_fsym = 0)
384 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
388 coff_obj_symbol_new_hook (symbolP)
391 long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
392 char * s = (char *) xmalloc (sz);
395 coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s;
397 S_SET_DATA_TYPE (symbolP, T_NULL);
398 S_SET_STORAGE_CLASS (symbolP, 0);
399 S_SET_NUMBER_AUXILIARY (symbolP, 0);
401 if (S_IS_STRING (symbolP))
402 SF_SET_STRING (symbolP);
404 if (S_IS_LOCAL (symbolP))
405 SF_SET_LOCAL (symbolP);
410 * Handle .ln directives.
413 static symbolS *current_lineno_sym;
414 static struct line_no *line_nos;
415 /* @@ Blindly assume all .ln directives will be in the .text section... */
419 add_lineno (frag, offset, num)
424 struct line_no *new_line =
425 (struct line_no *) xmalloc (sizeof (struct line_no));
426 if (!current_lineno_sym)
432 /* The native aix assembler accepts negative line number */
436 /* Zero is used as an end marker in the file. */
437 as_warn (_("Line numbers must be positive integers\n"));
440 #endif /* OBJ_XCOFF */
441 new_line->next = line_nos;
442 new_line->frag = frag;
443 new_line->l.line_number = num;
444 new_line->l.u.offset = offset;
450 coff_add_linesym (sym)
455 coffsymbol (symbol_get_bfdsym (current_lineno_sym))->lineno =
460 current_lineno_sym = sym;
464 obj_coff_ln (appline)
469 if (! appline && def_symbol_in_progress != NULL)
471 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
472 demand_empty_rest_of_line ();
476 l = get_absolute_expression ();
478 /* If there is no lineno symbol, treat a .ln
479 directive as if it were a .appline directive. */
480 if (appline || current_lineno_sym == NULL)
481 new_logical_line ((char *) NULL, l - 1);
483 add_lineno (frag_now, frag_now_fix (), l);
492 l += coff_line_base - 1;
493 listing_source_line (l);
498 demand_empty_rest_of_line ();
501 /* .loc is essentially the same as .ln; parse it for assembler
505 obj_coff_loc (ignore)
506 int ignore ATTRIBUTE_UNUSED;
510 /* FIXME: Why do we need this check? We need it for ECOFF, but why
511 do we need it for COFF? */
512 if (now_seg != text_section)
514 as_warn (_(".loc outside of .text"));
515 demand_empty_rest_of_line ();
519 if (def_symbol_in_progress != NULL)
521 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
522 demand_empty_rest_of_line ();
526 /* Skip the file number. */
528 get_absolute_expression ();
531 lineno = get_absolute_expression ();
539 lineno += coff_line_base - 1;
540 listing_source_line (lineno);
545 demand_empty_rest_of_line ();
547 add_lineno (frag_now, frag_now_fix (), lineno);
550 /* Handle the .ident pseudo-op. */
553 obj_coff_ident (ignore)
554 int ignore ATTRIBUTE_UNUSED;
556 segT current_seg = now_seg;
557 subsegT current_subseg = now_subseg;
563 /* We could put it in .comment, but that creates an extra section
564 that shouldn't be loaded into memory, which requires linker
565 changes... For now, until proven otherwise, use .rdata. */
566 sec = subseg_new (".rdata$zzz", 0);
567 bfd_set_section_flags (stdoutput, sec,
568 ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)
569 & bfd_applicable_section_flags (stdoutput)));
572 subseg_new (".comment", 0);
576 subseg_set (current_seg, current_subseg);
582 * Handle .def directives.
584 * One might ask : why can't we symbol_new if the symbol does not
585 * already exist and fill it with debug information. Because of
586 * the C_EFCN special symbol. It would clobber the value of the
587 * function symbol before we have a chance to notice that it is
588 * a C_EFCN. And a second reason is that the code is more clear this
589 * way. (at least I think it is :-).
593 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
594 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
595 *input_line_pointer == '\t') \
596 input_line_pointer++;
600 int what ATTRIBUTE_UNUSED;
602 char name_end; /* Char after the end of name */
603 char *symbol_name; /* Name of the debug symbol */
604 char *symbol_name_copy; /* Temporary copy of the name */
605 unsigned int symbol_name_length;
607 if (def_symbol_in_progress != NULL)
609 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
610 demand_empty_rest_of_line ();
612 } /* if not inside .def/.endef */
616 symbol_name = input_line_pointer;
617 #ifdef STRIP_UNDERSCORE
618 if (symbol_name[0] == '_' && symbol_name[1] != 0)
620 #endif /* STRIP_UNDERSCORE */
622 name_end = get_symbol_end ();
623 symbol_name_length = strlen (symbol_name);
624 symbol_name_copy = xmalloc (symbol_name_length + 1);
625 strcpy (symbol_name_copy, symbol_name);
626 #ifdef tc_canonicalize_symbol_name
627 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
630 /* Initialize the new symbol */
631 def_symbol_in_progress = symbol_make (symbol_name_copy);
632 symbol_set_frag (def_symbol_in_progress, &zero_address_frag);
633 S_SET_VALUE (def_symbol_in_progress, 0);
635 if (S_IS_STRING (def_symbol_in_progress))
636 SF_SET_STRING (def_symbol_in_progress);
638 *input_line_pointer = name_end;
640 demand_empty_rest_of_line ();
643 unsigned int dim_index;
646 obj_coff_endef (ignore)
647 int ignore ATTRIBUTE_UNUSED;
649 symbolS *symbolP = NULL;
653 if (def_symbol_in_progress == NULL)
655 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
656 demand_empty_rest_of_line ();
658 } /* if not inside .def/.endef */
660 /* Set the section number according to storage class. */
661 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
666 SF_SET_TAG (def_symbol_in_progress);
667 /* intentional fallthrough */
670 SF_SET_DEBUG (def_symbol_in_progress);
671 S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());
675 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
676 /* intentional fallthrough */
678 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
679 /* intentional fallthrough */
683 S_SET_SEGMENT (def_symbol_in_progress, text_section);
685 name = S_GET_NAME (def_symbol_in_progress);
686 if (name[0] == '.' && name[2] == 'f' && name[3] == '\0')
692 if (! in_function ())
693 as_warn (_("`%s' symbol without preceding function"), name);
694 /* Will need relocating. */
695 SF_SET_PROCESS (def_symbol_in_progress);
701 /* The MS compilers output the actual endline, not the
702 function-relative one... we want to match without
703 changing the assembler input. */
704 SA_SET_SYM_LNNO (def_symbol_in_progress,
705 (SA_GET_SYM_LNNO (def_symbol_in_progress)
716 #endif /* C_AUTOARG */
723 /* According to the COFF documentation:
725 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
727 A special section number (-2) marks symbolic debugging symbols,
728 including structure/union/enumeration tag names, typedefs, and
729 the name of the file. A section number of -1 indicates that the
730 symbol has a value but is not relocatable. Examples of
731 absolute-valued symbols include automatic and register variables,
732 function arguments, and .eos symbols.
734 But from Ian Lance Taylor:
736 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
738 the actual tools all marked them as section -1. So the GNU COFF
739 assembler follows historical COFF assemblers.
741 However, it causes problems for djgpp
743 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
745 By defining STRICTCOFF, a COFF port can make the assembler to
746 follow the documented behavior. */
753 SF_SET_DEBUG (def_symbol_in_progress);
754 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
762 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
773 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
780 as_warn (_("unexpected storage class %d"),
781 S_GET_STORAGE_CLASS (def_symbol_in_progress));
783 } /* switch on storage class */
785 /* Now that we have built a debug symbol, try to find if we should
786 merge with an existing symbol or not. If a symbol is C_EFCN or
787 absolute_section or untagged SEG_DEBUG it never merges. We also
788 don't merge labels, which are in a different namespace, nor
789 symbols which have not yet been defined since they are typically
790 unique, nor do we merge tags with non-tags. */
792 /* Two cases for functions. Either debug followed by definition or
793 definition followed by debug. For definition first, we will
794 merge the debug symbol into the definition. For debug first, the
795 lineno entry MUST point to the definition function or else it
796 will point off into space when obj_crawl_symbol_chain() merges
797 the debug symbol into the real symbol. Therefor, let's presume
798 the debug symbol is a real function reference. */
800 /* FIXME-SOON If for some reason the definition label/symbol is
801 never seen, this will probably leave an undefined symbol at link
804 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
805 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
806 || (!strcmp (bfd_get_section_name (stdoutput,
807 S_GET_SEGMENT (def_symbol_in_progress)),
809 && !SF_GET_TAG (def_symbol_in_progress))
810 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
811 || ! symbol_constant_p (def_symbol_in_progress)
812 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
813 DO_NOT_STRIP)) == NULL
814 || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))
816 /* If it already is at the end of the symbol list, do nothing */
817 if (def_symbol_in_progress != symbol_lastP)
819 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
820 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
826 /* This symbol already exists, merge the newly created symbol
827 into the old one. This is not mandatory. The linker can
828 handle duplicate symbols correctly. But I guess that it save
829 a *lot* of space if the assembly file defines a lot of
832 /* The debug entry (def_symbol_in_progress) is merged into the
833 previous definition. */
835 c_symbol_merge (def_symbol_in_progress, symbolP);
836 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
838 def_symbol_in_progress = symbolP;
840 if (SF_GET_FUNCTION (def_symbol_in_progress)
841 || SF_GET_TAG (def_symbol_in_progress)
842 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
844 /* For functions, and tags, and static symbols, the symbol
845 *must* be where the debug symbol appears. Move the
846 existing symbol to the current place. */
847 /* If it already is at the end of the symbol list, do nothing */
848 if (def_symbol_in_progress != symbol_lastP)
850 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
851 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);
856 if (SF_GET_TAG (def_symbol_in_progress))
860 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
862 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
863 tag_insert (S_GET_NAME (def_symbol_in_progress),
864 def_symbol_in_progress);
867 if (SF_GET_FUNCTION (def_symbol_in_progress))
869 know (sizeof (def_symbol_in_progress) <= sizeof (long));
870 set_function (def_symbol_in_progress);
871 SF_SET_PROCESS (def_symbol_in_progress);
875 /* That is, if this is the first time we've seen the
877 symbol_table_insert (def_symbol_in_progress);
878 } /* definition follows debug */
879 } /* Create the line number entry pointing to the function being defined */
881 def_symbol_in_progress = NULL;
882 demand_empty_rest_of_line ();
886 obj_coff_dim (ignore)
887 int ignore ATTRIBUTE_UNUSED;
891 if (def_symbol_in_progress == NULL)
893 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
894 demand_empty_rest_of_line ();
896 } /* if not inside .def/.endef */
898 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
900 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
903 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
904 get_absolute_expression ());
906 switch (*input_line_pointer)
909 input_line_pointer++;
913 as_warn (_("badly formed .dim directive ignored"));
914 /* intentional fallthrough */
922 demand_empty_rest_of_line ();
926 obj_coff_line (ignore)
927 int ignore ATTRIBUTE_UNUSED;
931 if (def_symbol_in_progress == NULL)
933 /* Probably stabs-style line? */
938 this_base = get_absolute_expression ();
939 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress)))
940 coff_line_base = this_base;
942 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
943 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
945 demand_empty_rest_of_line ();
948 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0)
953 listing_source_line ((unsigned int) this_base);
959 obj_coff_size (ignore)
960 int ignore ATTRIBUTE_UNUSED;
962 if (def_symbol_in_progress == NULL)
964 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
965 demand_empty_rest_of_line ();
967 } /* if not inside .def/.endef */
969 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
970 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
971 demand_empty_rest_of_line ();
975 obj_coff_scl (ignore)
976 int ignore ATTRIBUTE_UNUSED;
978 if (def_symbol_in_progress == NULL)
980 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
981 demand_empty_rest_of_line ();
983 } /* if not inside .def/.endef */
985 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
986 demand_empty_rest_of_line ();
990 obj_coff_tag (ignore)
991 int ignore ATTRIBUTE_UNUSED;
996 if (def_symbol_in_progress == NULL)
998 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
999 demand_empty_rest_of_line ();
1003 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
1004 symbol_name = input_line_pointer;
1005 name_end = get_symbol_end ();
1007 #ifdef tc_canonicalize_symbol_name
1008 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1011 /* Assume that the symbol referred to by .tag is always defined.
1012 This was a bad assumption. I've added find_or_make. xoxorich. */
1013 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
1014 tag_find_or_make (symbol_name));
1015 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
1017 as_warn (_("tag not found for .tag %s"), symbol_name);
1020 SF_SET_TAGGED (def_symbol_in_progress);
1021 *input_line_pointer = name_end;
1023 demand_empty_rest_of_line ();
1027 obj_coff_type (ignore)
1028 int ignore ATTRIBUTE_UNUSED;
1030 if (def_symbol_in_progress == NULL)
1032 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1033 demand_empty_rest_of_line ();
1035 } /* if not inside .def/.endef */
1037 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
1039 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
1040 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
1042 SF_SET_FUNCTION (def_symbol_in_progress);
1043 } /* is a function */
1045 demand_empty_rest_of_line ();
1049 obj_coff_val (ignore)
1050 int ignore ATTRIBUTE_UNUSED;
1052 if (def_symbol_in_progress == NULL)
1054 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1055 demand_empty_rest_of_line ();
1057 } /* if not inside .def/.endef */
1059 if (is_name_beginner (*input_line_pointer))
1061 char *symbol_name = input_line_pointer;
1062 char name_end = get_symbol_end ();
1064 #ifdef tc_canonicalize_symbol_name
1065 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1067 if (!strcmp (symbol_name, "."))
1069 symbol_set_frag (def_symbol_in_progress, frag_now);
1070 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
1071 /* If the .val is != from the .def (e.g. statics) */
1073 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
1077 exp.X_op = O_symbol;
1078 exp.X_add_symbol = symbol_find_or_make (symbol_name);
1079 exp.X_op_symbol = NULL;
1080 exp.X_add_number = 0;
1081 symbol_set_value_expression (def_symbol_in_progress, &exp);
1083 /* If the segment is undefined when the forward reference is
1084 resolved, then copy the segment id from the forward
1086 SF_SET_GET_SEGMENT (def_symbol_in_progress);
1088 /* FIXME: gcc can generate address expressions here in
1089 unusual cases (search for "obscure" in sdbout.c). We
1090 just ignore the offset here, thus generating incorrect
1091 debugging information. We ignore the rest of the line
1094 /* Otherwise, it is the name of a non debug symbol and its value
1095 will be calculated later. */
1096 *input_line_pointer = name_end;
1100 S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
1101 } /* if symbol based */
1103 demand_empty_rest_of_line ();
1108 /* Return nonzero if name begins with weak alternate symbol prefix. */
1111 weak_is_altname (const char * name)
1113 return ! strncmp (name, weak_altprefix, sizeof (weak_altprefix) - 1);
1116 /* Return the name of the alternate symbol
1117 name corresponding to a weak symbol's name. */
1120 weak_name2altname (const char * name)
1124 alt_name = xmalloc (sizeof (weak_altprefix) + strlen (name));
1125 strcpy (alt_name, weak_altprefix);
1126 return strcat (alt_name, name);
1129 /* Return the name of the weak symbol corresponding to an
1133 weak_altname2name (const char * name)
1138 assert (weak_is_altname (name));
1140 weak_name = xstrdup (name + 6);
1141 if ((dot = strchr (weak_name, '.')))
1146 /* Make a weak symbol name unique by
1147 appending the name of an external symbol. */
1150 weak_uniquify (const char * name)
1153 const char * unique = "";
1156 if (an_external_name != NULL)
1157 unique = an_external_name;
1159 assert (weak_is_altname (name));
1161 if (strchr (name + sizeof (weak_altprefix), '.'))
1164 ret = xmalloc (strlen (name) + strlen (unique) + 2);
1167 strcat (ret, unique);
1173 /* Handle .weak. This is a GNU extension in formats other than PE. */
1176 obj_coff_weak (int ignore ATTRIBUTE_UNUSED)
1182 symbolS *alternateP;
1187 name = input_line_pointer;
1188 c = get_symbol_end ();
1191 as_warn (_("badly formed .weak directive ignored"));
1192 ignore_rest_of_line ();
1196 symbolP = symbol_find_or_make (name);
1197 *input_line_pointer = c;
1200 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
1201 S_SET_WEAK (symbolP);
1205 /* See _Microsoft Portable Executable and Common Object
1206 File Format Specification_, section 5.5.3.
1207 Create a symbol representing the alternate value.
1208 coff_frob_symbol will set the value of this symbol from
1209 the value of the weak symbol itself. */
1210 S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
1211 S_SET_NUMBER_AUXILIARY (symbolP, 1);
1212 SA_SET_SYM_FSIZE (symbolP, IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
1214 alternateP = symbol_find_or_make (weak_name2altname (name));
1215 S_SET_EXTERNAL (alternateP);
1216 S_SET_STORAGE_CLASS (alternateP, C_NT_WEAK);
1218 SA_SET_SYM_TAGNDX (symbolP, alternateP);
1223 input_line_pointer++;
1225 if (*input_line_pointer == '\n')
1232 demand_empty_rest_of_line ();
1236 coff_obj_read_begin_hook ()
1238 /* These had better be the same. Usually 18 bytes. */
1240 know (sizeof (SYMENT) == sizeof (AUXENT));
1241 know (SYMESZ == AUXESZ);
1246 symbolS *coff_last_function;
1248 static symbolS *coff_last_bf;
1252 coff_frob_symbol (symp, punt)
1256 static symbolS *last_tagP;
1257 static stack *block_stack;
1258 static symbolS *set_end;
1259 symbolS *next_set_end = NULL;
1261 if (symp == &abs_symbol)
1267 if (current_lineno_sym)
1268 coff_add_linesym ((symbolS *) 0);
1271 block_stack = stack_init (512, sizeof (symbolS*));
1274 if (S_GET_STORAGE_CLASS (symp) == C_NT_WEAK
1275 && ! S_IS_WEAK (symp)
1276 && weak_is_altname (S_GET_NAME (symp)))
1278 /* This is a weak alternate symbol. All processing of
1279 PECOFFweak symbols is done here, through the alternate. */
1280 symbolS *weakp = symbol_find (weak_altname2name (S_GET_NAME (symp)));
1283 assert (S_GET_NUMBER_AUXILIARY (weakp) == 1);
1285 if (symbol_equated_p (weakp))
1287 /* The weak symbol has an alternate specified; symp is unneeded. */
1288 S_SET_STORAGE_CLASS (weakp, C_NT_WEAK);
1289 SA_SET_SYM_TAGNDX (weakp,
1290 symbol_get_value_expression (weakp)->X_add_symbol);
1292 S_CLEAR_EXTERNAL (symp);
1298 /* The weak symbol has been assigned an alternate value.
1299 Copy this value to symp, and set symp as weakp's alternate. */
1300 if (S_GET_STORAGE_CLASS (weakp) != C_NT_WEAK)
1302 S_SET_STORAGE_CLASS (symp, S_GET_STORAGE_CLASS (weakp));
1303 S_SET_STORAGE_CLASS (weakp, C_NT_WEAK);
1306 if (S_IS_DEFINED (weakp))
1308 /* This is a defined weak symbol. Copy value information
1309 from the weak symbol itself to the alternate symbol. */
1310 symbol_set_value_expression (symp,
1311 symbol_get_value_expression (weakp));
1312 symbol_set_frag (symp, symbol_get_frag (weakp));
1313 S_SET_SEGMENT (symp, S_GET_SEGMENT (weakp));
1317 /* This is an undefined weak symbol.
1318 Define the alternate symbol to zero. */
1319 S_SET_VALUE (symp, 0);
1320 S_SET_SEGMENT (symp, absolute_section);
1323 S_SET_NAME (symp, weak_uniquify (S_GET_NAME (symp)));
1324 S_SET_STORAGE_CLASS (symp, C_EXT);
1326 S_SET_VALUE (weakp, 0);
1327 S_SET_SEGMENT (weakp, undefined_section);
1331 if (S_IS_WEAK (symp))
1332 S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
1335 if (!S_IS_DEFINED (symp)
1336 && !S_IS_WEAK (symp)
1337 && S_GET_STORAGE_CLASS (symp) != C_STAT)
1338 S_SET_STORAGE_CLASS (symp, C_EXT);
1340 if (!SF_GET_DEBUG (symp))
1344 if (!SF_GET_LOCAL (symp)
1345 && !SF_GET_STATICS (symp)
1346 && S_GET_STORAGE_CLASS (symp) != C_LABEL
1347 && symbol_constant_p(symp)
1348 && (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
1349 && S_GET_STORAGE_CLASS (real) == C_NULL
1352 c_symbol_merge (symp, real);
1357 if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp))
1359 assert (S_GET_VALUE (symp) == 0);
1360 S_SET_EXTERNAL (symp);
1362 else if (S_GET_STORAGE_CLASS (symp) == C_NULL)
1364 if (S_GET_SEGMENT (symp) == text_section
1365 && symp != seg_info (text_section)->sym)
1366 S_SET_STORAGE_CLASS (symp, C_LABEL);
1368 S_SET_STORAGE_CLASS (symp, C_STAT);
1371 if (SF_GET_PROCESS (symp))
1373 if (S_GET_STORAGE_CLASS (symp) == C_BLOCK)
1375 if (!strcmp (S_GET_NAME (symp), ".bb"))
1376 stack_push (block_stack, (char *) &symp);
1381 begin = *(symbolS **) stack_pop (block_stack);
1383 as_warn (_("mismatched .eb"));
1385 next_set_end = begin;
1389 if (coff_last_function == 0 && SF_GET_FUNCTION (symp))
1391 union internal_auxent *auxp;
1393 coff_last_function = symp;
1394 if (S_GET_NUMBER_AUXILIARY (symp) < 1)
1395 S_SET_NUMBER_AUXILIARY (symp, 1);
1396 auxp = SYM_AUXENT (symp);
1397 memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0,
1398 sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen));
1401 if (S_GET_STORAGE_CLASS (symp) == C_EFCN)
1403 if (coff_last_function == 0)
1404 as_fatal (_("C_EFCN symbol out of scope"));
1405 SA_SET_SYM_FSIZE (coff_last_function,
1406 (long) (S_GET_VALUE (symp)
1407 - S_GET_VALUE (coff_last_function)));
1408 next_set_end = coff_last_function;
1409 coff_last_function = 0;
1413 if (S_IS_EXTERNAL (symp))
1414 S_SET_STORAGE_CLASS (symp, C_EXT);
1415 else if (SF_GET_LOCAL (symp))
1418 if (SF_GET_FUNCTION (symp))
1419 symbol_get_bfdsym (symp)->flags |= BSF_FUNCTION;
1424 /* Double check weak symbols. */
1425 if (S_IS_WEAK (symp) && S_IS_COMMON (symp))
1426 as_bad (_("Symbol `%s' can not be both weak and common"),
1429 if (SF_GET_TAG (symp))
1431 else if (S_GET_STORAGE_CLASS (symp) == C_EOS)
1432 next_set_end = last_tagP;
1435 /* This is pretty horrible, but we have to set *punt correctly in
1436 order to call SA_SET_SYM_ENDNDX correctly. */
1437 if (! symbol_used_in_reloc_p (symp)
1438 && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0
1439 || (! (S_IS_EXTERNAL (symp) || S_IS_WEAK (symp))
1440 && ! symbol_get_tc (symp)->output
1441 && S_GET_STORAGE_CLASS (symp) != C_FILE)))
1445 if (set_end != (symbolS *) NULL
1447 && ((symbol_get_bfdsym (symp)->flags & BSF_NOT_AT_END) != 0
1448 || (S_IS_DEFINED (symp)
1449 && ! S_IS_COMMON (symp)
1450 && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp)))))
1452 SA_SET_SYM_ENDNDX (set_end, symp);
1456 if (next_set_end != NULL)
1458 if (set_end != NULL)
1459 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1460 S_GET_NAME (set_end));
1461 set_end = next_set_end;
1466 && S_GET_STORAGE_CLASS (symp) == C_FCN
1467 && strcmp (S_GET_NAME (symp), ".bf") == 0)
1469 if (coff_last_bf != NULL)
1470 SA_SET_SYM_ENDNDX (coff_last_bf, symp);
1471 coff_last_bf = symp;
1474 if (coffsymbol (symbol_get_bfdsym (symp))->lineno)
1477 struct line_no *lptr;
1480 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1481 for (i = 0; lptr; lptr = lptr->next)
1483 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1485 /* We need i entries for line numbers, plus 1 for the first
1486 entry which BFD will override, plus 1 for the last zero
1487 entry (a marker for BFD). */
1488 l = (alent *) xmalloc ((i + 2) * sizeof (alent));
1489 coffsymbol (symbol_get_bfdsym (symp))->lineno = l;
1490 l[i + 1].line_number = 0;
1491 l[i + 1].u.sym = NULL;
1495 lptr->l.u.offset += lptr->frag->fr_address / OCTETS_PER_BYTE;
1503 coff_adjust_section_syms (abfd, sec, x)
1504 bfd *abfd ATTRIBUTE_UNUSED;
1506 PTR x ATTRIBUTE_UNUSED;
1509 segment_info_type *seginfo = seg_info (sec);
1510 int nlnno, nrelocs = 0;
1512 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1513 tc-ppc.c. Do not get confused by it. */
1514 if (seginfo == NULL)
1517 if (!strcmp (sec->name, ".text"))
1518 nlnno = coff_n_line_nos;
1522 /* @@ Hope that none of the fixups expand to more than one reloc
1524 fixS *fixp = seginfo->fix_root;
1527 if (! fixp->fx_done)
1529 fixp = fixp->fx_next;
1532 if (bfd_get_section_size (sec) == 0
1535 && sec != text_section
1536 && sec != data_section
1537 && sec != bss_section)
1539 secsym = section_symbol (sec);
1540 /* This is an estimate; we'll plug in the real value using
1541 SET_SECTION_RELOCS later */
1542 SA_SET_SCN_NRELOC (secsym, nrelocs);
1543 SA_SET_SCN_NLINNO (secsym, nlnno);
1547 coff_frob_file_after_relocs ()
1549 bfd_map_over_sections (stdoutput, coff_adjust_section_syms, (char*) 0);
1552 /* Implement the .section pseudo op:
1553 .section name {, "flags"}
1555 | +--- optional flags: 'b' for bss
1557 +-- section name 'l' for lib
1561 'd' (apparently m88k for data)
1563 'r' for read-only data
1564 's' for shared data (PE)
1565 But if the argument is not a quoted string, treat it as a
1568 Note the 'a' flag is silently ignored. This allows the same
1569 .section directive to be parsed in both ELF and COFF formats. */
1572 obj_coff_section (ignore)
1573 int ignore ATTRIBUTE_UNUSED;
1575 /* Strip out the section name */
1580 flagword flags, oldflags;
1591 section_name = input_line_pointer;
1592 c = get_symbol_end ();
1594 name = xmalloc (input_line_pointer - section_name + 1);
1595 strcpy (name, section_name);
1597 *input_line_pointer = c;
1602 flags = SEC_NO_FLAGS;
1604 if (*input_line_pointer == ',')
1606 ++input_line_pointer;
1608 if (*input_line_pointer != '"')
1609 exp = get_absolute_expression ();
1612 ++input_line_pointer;
1613 while (*input_line_pointer != '"'
1614 && ! is_end_of_line[(unsigned char) *input_line_pointer])
1616 switch (*input_line_pointer)
1618 case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
1619 case 'n': flags &=~ SEC_LOAD; flags |= SEC_NEVER_LOAD; break;
1621 case 's': flags |= SEC_SHARED; /* fall through */
1622 case 'd': flags |= SEC_DATA | SEC_LOAD; /* fall through */
1623 case 'w': flags &=~ SEC_READONLY; break;
1625 case 'a': break; /* For compatibility with ELF. */
1626 case 'x': flags |= SEC_CODE | SEC_LOAD; break;
1627 case 'r': flags |= SEC_DATA | SEC_LOAD | SEC_READONLY; break;
1629 case 'i': /* STYP_INFO */
1630 case 'l': /* STYP_LIB */
1631 case 'o': /* STYP_OVER */
1632 as_warn (_("unsupported section attribute '%c'"),
1633 *input_line_pointer);
1637 as_warn(_("unknown section attribute '%c'"),
1638 *input_line_pointer);
1641 ++input_line_pointer;
1643 if (*input_line_pointer == '"')
1644 ++input_line_pointer;
1648 sec = subseg_new (name, (subsegT) exp);
1650 oldflags = bfd_get_section_flags (stdoutput, sec);
1651 if (oldflags == SEC_NO_FLAGS)
1653 /* Set section flags for a new section just created by subseg_new.
1654 Provide a default if no flags were parsed. */
1655 if (flags == SEC_NO_FLAGS)
1656 flags = TC_COFF_SECTION_DEFAULT_ATTRIBUTES;
1658 #ifdef COFF_LONG_SECTION_NAMES
1659 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1660 sections so adjust_reloc_syms in write.c will correctly handle
1661 relocs which refer to non-local symbols in these sections. */
1662 if (strncmp (name, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1663 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1666 if (! bfd_set_section_flags (stdoutput, sec, flags))
1667 as_warn (_("error setting flags for \"%s\": %s"),
1668 bfd_section_name (stdoutput, sec),
1669 bfd_errmsg (bfd_get_error ()));
1671 else if (flags != SEC_NO_FLAGS)
1673 /* This section's attributes have already been set. Warn if the
1674 attributes don't match. */
1675 flagword matchflags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
1676 | SEC_DATA | SEC_SHARED | SEC_NEVER_LOAD);
1677 if ((flags ^ oldflags) & matchflags)
1678 as_warn (_("Ignoring changed section attributes for %s"), name);
1681 demand_empty_rest_of_line ();
1685 coff_adjust_symtab ()
1687 if (symbol_rootP == NULL
1688 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
1689 c_dot_file_symbol ("fake", 0);
1693 coff_frob_section (sec)
1699 bfd_vma size, n_entries, mask;
1700 bfd_vma align_power = (bfd_vma)sec->alignment_power + OCTETS_PER_BYTE_POWER;
1702 /* The COFF back end in BFD requires that all section sizes be
1703 rounded up to multiples of the corresponding section alignments,
1704 supposedly because standard COFF has no other way of encoding alignment
1705 for sections. If your COFF flavor has a different way of encoding
1706 section alignment, then skip this step, as TICOFF does. */
1707 size = bfd_get_section_size (sec);
1708 mask = ((bfd_vma) 1 << align_power) - 1;
1709 #if !defined(TICOFF)
1715 new_size = (size + mask) & ~mask;
1716 bfd_set_section_size (stdoutput, sec, new_size);
1718 /* If the size had to be rounded up, add some padding in
1719 the last non-empty frag. */
1720 fragp = seg_info (sec)->frchainP->frch_root;
1721 last = seg_info (sec)->frchainP->frch_last;
1722 while (fragp->fr_next != last)
1723 fragp = fragp->fr_next;
1724 last->fr_address = size;
1725 fragp->fr_offset += new_size - size;
1729 /* If the section size is non-zero, the section symbol needs an aux
1730 entry associated with it, indicating the size. We don't know
1731 all the values yet; coff_frob_symbol will fill them in later. */
1734 || sec == text_section
1735 || sec == data_section
1736 || sec == bss_section)
1739 symbolS *secsym = section_symbol (sec);
1741 S_SET_STORAGE_CLASS (secsym, C_STAT);
1742 S_SET_NUMBER_AUXILIARY (secsym, 1);
1743 SF_SET_STATICS (secsym);
1744 SA_SET_SCN_SCNLEN (secsym, size);
1747 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1748 #ifndef STAB_SECTION_NAME
1749 #define STAB_SECTION_NAME ".stab"
1751 #ifndef STAB_STRING_SECTION_NAME
1752 #define STAB_STRING_SECTION_NAME ".stabstr"
1754 if (strcmp (STAB_STRING_SECTION_NAME, sec->name))
1758 sec = subseg_get (STAB_SECTION_NAME, 0);
1759 /* size is already rounded up, since other section will be listed first */
1760 size = bfd_get_section_size (strsec);
1762 n_entries = bfd_get_section_size (sec) / 12 - 1;
1764 /* Find first non-empty frag. It should be large enough. */
1765 fragp = seg_info (sec)->frchainP->frch_root;
1766 while (fragp && fragp->fr_fix == 0)
1767 fragp = fragp->fr_next;
1768 assert (fragp != 0 && fragp->fr_fix >= 12);
1770 /* Store the values. */
1771 p = fragp->fr_literal;
1772 bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6);
1773 bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8);
1777 obj_coff_init_stab_section (seg)
1783 unsigned int stroff;
1785 /* Make space for this first symbol. */
1789 as_where (&file, (unsigned int *) NULL);
1790 stabstr_name = (char *) xmalloc (strlen (seg->name) + 4);
1791 strcpy (stabstr_name, seg->name);
1792 strcat (stabstr_name, "str");
1793 stroff = get_stab_string_offset (file, stabstr_name);
1795 md_number_to_chars (p, stroff, 4);
1804 return ((s == NULL) ? "(NULL)" : S_GET_NAME (s));
1812 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
1814 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1815 (unsigned long) symbolP,
1816 S_GET_NAME(symbolP),
1817 (long) S_GET_DATA_TYPE(symbolP),
1818 S_GET_STORAGE_CLASS(symbolP),
1819 (int) S_GET_SEGMENT(symbolP));
1825 #else /* not BFD_ASSEMBLER */
1828 /* This is needed because we include internal bfd things. */
1832 #include "libcoff.h"
1834 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1835 that we can stick sections together without causing trouble. */
1837 #define NOP_OPCODE 0x00
1840 /* The zeroes if symbol name is longer than 8 chars */
1841 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1843 #define MIN(a,b) ((a) < (b)? (a) : (b))
1845 /* This vector is used to turn a gas internal segment number into a
1846 section number suitable for insertion into a coff symbol table.
1847 This must correspond to seg_info_off_by_4. */
1849 const short seg_N_TYPE[] =
1850 { /* in: segT out: N_TYPE bits */
1852 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1853 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1854 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1855 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1856 C_UNDEF_SECTION, /* SEG_UNKNOWN */
1857 C_UNDEF_SECTION, /* SEG_GOOF */
1858 C_UNDEF_SECTION, /* SEG_EXPR */
1859 C_DEBUG_SECTION, /* SEG_DEBUG */
1860 C_NTV_SECTION, /* SEG_NTV */
1861 C_PTV_SECTION, /* SEG_PTV */
1862 C_REGISTER_SECTION, /* SEG_REGISTER */
1865 int function_lineoff = -1; /* Offset in line#s where the last function
1866 started (the odd entry for line #0) */
1868 /* Structure used to keep the filenames which
1869 are too long around so that we can stick them
1870 into the string table. */
1871 struct filename_list
1874 struct filename_list *next;
1877 static struct filename_list *filename_list_head;
1878 static struct filename_list *filename_list_tail;
1880 static symbolS *last_line_symbol;
1882 /* Add 4 to the real value to get the index and compensate the
1883 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1884 section number into a segment number. */
1887 static symbolS *previous_file_symbol;
1888 static int line_base;
1890 void c_symbol_merge PARAMS ((symbolS *, symbolS *));
1891 symbolS *c_section_symbol PARAMS ((char *, int));
1892 void obj_coff_section PARAMS ((int));
1893 void do_relocs_for PARAMS ((bfd *, object_headers *, unsigned long *));
1894 char * symbol_to_chars PARAMS ((bfd *, char *, symbolS *));
1895 void w_strings PARAMS ((char *));
1897 static void fixup_segment PARAMS ((segment_info_type *, segT));
1898 static void fixup_mdeps PARAMS ((fragS *, object_headers *, segT));
1899 static void fill_section PARAMS ((bfd *, object_headers *, unsigned long *));
1900 static int c_line_new PARAMS ((symbolS *, long, int, fragS *));
1901 static void w_symbols PARAMS ((bfd *, char *, symbolS *));
1902 static void adjust_stab_section PARAMS ((bfd *, segT));
1903 static void obj_coff_lcomm PARAMS ((int));
1904 static void obj_coff_text PARAMS ((int));
1905 static void obj_coff_data PARAMS ((int));
1906 static unsigned int count_entries_in_chain PARAMS ((unsigned int));
1907 static void coff_header_append PARAMS ((bfd *, object_headers *));
1908 static unsigned int yank_symbols PARAMS ((void));
1909 static unsigned int glue_symbols PARAMS ((symbolS **, symbolS **));
1910 static unsigned int tie_tags PARAMS ((void));
1911 static void crawl_symbols PARAMS ((object_headers *, bfd *));
1912 static void do_linenos_for PARAMS ((bfd *, object_headers *, unsigned long *));
1913 static void remove_subsegs PARAMS ((void));
1917 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1919 This array maps a COFF section number into a gas section number.
1920 Because COFF uses negative section numbers, you must add 4 to the
1921 COFF section number when indexing into this array; this is done via
1922 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1925 static const segT seg_info_off_by_4[] =
1932 SEG_E0, SEG_E1, SEG_E2, SEG_E3, SEG_E4,
1933 SEG_E5, SEG_E6, SEG_E7, SEG_E8, SEG_E9,
1934 SEG_E10, SEG_E11, SEG_E12, SEG_E13, SEG_E14,
1935 SEG_E15, SEG_E16, SEG_E17, SEG_E18, SEG_E19,
1936 SEG_E20, SEG_E21, SEG_E22, SEG_E23, SEG_E24,
1937 SEG_E25, SEG_E26, SEG_E27, SEG_E28, SEG_E29,
1938 SEG_E30, SEG_E31, SEG_E32, SEG_E33, SEG_E34,
1939 SEG_E35, SEG_E36, SEG_E37, SEG_E38, SEG_E39,
1952 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1954 static relax_addressT relax_align PARAMS ((relax_addressT, long));
1956 static relax_addressT
1957 relax_align (address, alignment)
1958 relax_addressT address;
1961 relax_addressT mask;
1962 relax_addressT new_address;
1964 mask = ~((~0) << alignment);
1965 new_address = (address + mask) & (~mask);
1966 return (new_address - address);
1973 return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum);
1976 static unsigned int size_section PARAMS ((bfd *, unsigned int));
1978 /* Calculate the size of the frag chain and fill in the section header
1979 to contain all of it, also fill in the addr of the sections. */
1982 size_section (abfd, idx)
1983 bfd *abfd ATTRIBUTE_UNUSED;
1986 unsigned int size = 0;
1987 fragS *frag = segment_info[idx].frchainP->frch_root;
1991 size = frag->fr_address;
1992 if (frag->fr_address != size)
1994 fprintf (stderr, _("Out of step\n"));
1995 size = frag->fr_address;
1998 switch (frag->fr_type)
2000 #ifdef TC_COFF_SIZEMACHDEP
2001 case rs_machine_dependent:
2002 size += TC_COFF_SIZEMACHDEP (frag);
2008 size += frag->fr_fix;
2009 size += frag->fr_offset * frag->fr_var;
2017 size += frag->fr_fix;
2018 off = relax_align (size, frag->fr_offset);
2019 if (frag->fr_subtype != 0 && off > frag->fr_subtype)
2025 BAD_CASE (frag->fr_type);
2028 frag = frag->fr_next;
2030 segment_info[idx].scnhdr.s_size = size;
2035 count_entries_in_chain (idx)
2038 unsigned int nrelocs;
2041 /* Count the relocations. */
2042 fixup_ptr = segment_info[idx].fix_root;
2044 while (fixup_ptr != (fixS *) NULL)
2046 if (fixup_ptr->fx_done == 0 && TC_COUNT_RELOC (fixup_ptr))
2048 #if defined(TC_A29K) || defined(TC_OR32)
2049 if (fixup_ptr->fx_r_type == RELOC_CONSTH)
2058 fixup_ptr = fixup_ptr->fx_next;
2065 static int compare_external_relocs PARAMS ((const PTR, const PTR));
2067 /* AUX's ld expects relocations to be sorted. */
2070 compare_external_relocs (x, y)
2074 struct external_reloc *a = (struct external_reloc *) x;
2075 struct external_reloc *b = (struct external_reloc *) y;
2076 bfd_vma aadr = bfd_getb32 (a->r_vaddr);
2077 bfd_vma badr = bfd_getb32 (b->r_vaddr);
2078 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
2083 /* Output all the relocations for a section. */
2086 do_relocs_for (abfd, h, file_cursor)
2089 unsigned long *file_cursor;
2091 unsigned int nrelocs;
2093 unsigned long reloc_start = *file_cursor;
2095 for (idx = SEG_E0; idx < SEG_LAST; idx++)
2097 if (segment_info[idx].scnhdr.s_name[0])
2099 struct external_reloc *ext_ptr;
2100 struct external_reloc *external_reloc_vec;
2101 unsigned int external_reloc_size;
2102 unsigned int base = segment_info[idx].scnhdr.s_paddr;
2103 fixS *fix_ptr = segment_info[idx].fix_root;
2104 nrelocs = count_entries_in_chain (idx);
2107 /* Bypass this stuff if no relocs. This also incidentally
2108 avoids a SCO bug, where free(malloc(0)) tends to crash. */
2110 external_reloc_size = nrelocs * RELSZ;
2111 external_reloc_vec =
2112 (struct external_reloc *) malloc (external_reloc_size);
2114 ext_ptr = external_reloc_vec;
2116 /* Fill in the internal coff style reloc struct from the
2117 internal fix list. */
2120 struct internal_reloc intr;
2122 /* Only output some of the relocations. */
2123 if (fix_ptr->fx_done == 0 && TC_COUNT_RELOC (fix_ptr))
2125 #ifdef TC_RELOC_MANGLE
2126 TC_RELOC_MANGLE (&segment_info[idx], fix_ptr, &intr,
2130 symbolS *symbol_ptr = fix_ptr->fx_addsy;
2132 intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr);
2134 base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where;
2136 #ifdef TC_KEEP_FX_OFFSET
2137 intr.r_offset = fix_ptr->fx_offset;
2142 while (symbol_ptr->sy_value.X_op == O_symbol
2143 && (! S_IS_DEFINED (symbol_ptr)
2144 || S_IS_COMMON (symbol_ptr)))
2148 /* We must avoid looping, as that can occur
2149 with a badly written program. */
2150 n = symbol_ptr->sy_value.X_add_symbol;
2151 if (n == symbol_ptr)
2156 /* Turn the segment of the symbol into an offset. */
2159 resolve_symbol_value (symbol_ptr);
2160 if (! symbol_ptr->sy_resolved)
2165 if (expr_symbol_where (symbol_ptr, &file, &line))
2166 as_bad_where (file, line,
2167 _("unresolved relocation"));
2169 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
2170 S_GET_NAME (symbol_ptr));
2173 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
2175 intr.r_symndx = dot->sy_number;
2177 intr.r_symndx = symbol_ptr->sy_number;
2182 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2184 #if defined(TC_A29K)
2185 /* The 29k has a special kludge for the high 16 bit
2186 reloc. Two relocations are emitted, R_IHIHALF,
2187 and R_IHCONST. The second one doesn't contain a
2188 symbol, but uses the value for offset. */
2189 if (intr.r_type == R_IHIHALF)
2191 /* Now emit the second bit. */
2192 intr.r_type = R_IHCONST;
2193 intr.r_symndx = fix_ptr->fx_addnumber;
2194 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2198 #if defined(TC_OR32)
2199 /* The or32 has a special kludge for the high 16 bit
2200 reloc. Two relocations are emitted, R_IHIHALF,
2201 and R_IHCONST. The second one doesn't contain a
2202 symbol, but uses the value for offset. */
2203 if (intr.r_type == R_IHIHALF)
2205 /* Now emit the second bit. */
2206 intr.r_type = R_IHCONST;
2207 intr.r_symndx = fix_ptr->fx_addnumber;
2208 (void) bfd_coff_swap_reloc_out (abfd, & intr, ext_ptr);
2214 fix_ptr = fix_ptr->fx_next;
2217 /* Sort the reloc table. */
2218 qsort ((PTR) external_reloc_vec, nrelocs,
2219 sizeof (struct external_reloc), compare_external_relocs);
2221 /* Write out the reloc table. */
2222 bfd_bwrite ((PTR) external_reloc_vec,
2223 (bfd_size_type) external_reloc_size, abfd);
2224 free (external_reloc_vec);
2226 /* Fill in section header info. */
2227 segment_info[idx].scnhdr.s_relptr = *file_cursor;
2228 *file_cursor += external_reloc_size;
2229 segment_info[idx].scnhdr.s_nreloc = nrelocs;
2234 segment_info[idx].scnhdr.s_relptr = 0;
2239 /* Set relocation_size field in file headers. */
2240 H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0);
2243 /* Run through a frag chain and write out the data to go with it, fill
2244 in the scnhdrs with the info on the file positions. */
2247 fill_section (abfd, h, file_cursor)
2249 object_headers *h ATTRIBUTE_UNUSED;
2250 unsigned long *file_cursor;
2253 unsigned int paddr = 0;
2255 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
2257 unsigned int offset = 0;
2258 struct internal_scnhdr *s = &(segment_info[i].scnhdr);
2264 fragS *frag = segment_info[i].frchainP->frch_root;
2265 char *buffer = NULL;
2271 buffer = xmalloc (s->s_size);
2272 s->s_scnptr = *file_cursor;
2274 know (s->s_paddr == paddr);
2276 if (strcmp (s->s_name, ".text") == 0)
2277 s->s_flags |= STYP_TEXT;
2278 else if (strcmp (s->s_name, ".data") == 0)
2279 s->s_flags |= STYP_DATA;
2280 else if (strcmp (s->s_name, ".bss") == 0)
2283 s->s_flags |= STYP_BSS;
2285 /* @@ Should make the i386 and a29k coff targets define
2286 COFF_NOLOAD_PROBLEM, and have only one test here. */
2290 #ifndef COFF_NOLOAD_PROBLEM
2291 /* Apparently the SVR3 linker (and exec syscall) and UDI
2292 mondfe progrem are confused by noload sections. */
2293 s->s_flags |= STYP_NOLOAD;
2299 else if (strcmp (s->s_name, ".lit") == 0)
2300 s->s_flags = STYP_LIT | STYP_TEXT;
2301 else if (strcmp (s->s_name, ".init") == 0)
2302 s->s_flags |= STYP_TEXT;
2303 else if (strcmp (s->s_name, ".fini") == 0)
2304 s->s_flags |= STYP_TEXT;
2305 else if (strncmp (s->s_name, ".comment", 8) == 0)
2306 s->s_flags |= STYP_INFO;
2310 unsigned int fill_size;
2311 switch (frag->fr_type)
2313 case rs_machine_dependent:
2316 memcpy (buffer + frag->fr_address,
2318 (unsigned int) frag->fr_fix);
2319 offset += frag->fr_fix;
2331 memcpy (buffer + frag->fr_address,
2333 (unsigned int) frag->fr_fix);
2334 offset += frag->fr_fix;
2337 fill_size = frag->fr_var;
2338 if (fill_size && frag->fr_offset > 0)
2341 unsigned int off = frag->fr_fix;
2342 for (count = frag->fr_offset; count; count--)
2344 if (fill_size + frag->fr_address + off <= s->s_size)
2346 memcpy (buffer + frag->fr_address + off,
2347 frag->fr_literal + frag->fr_fix,
2350 offset += fill_size;
2355 case rs_broken_word:
2360 frag = frag->fr_next;
2365 if (s->s_scnptr != 0)
2367 bfd_bwrite (buffer, s->s_size, abfd);
2368 *file_cursor += s->s_size;
2377 /* Coff file generation & utilities. */
2380 coff_header_append (abfd, h)
2387 #ifdef COFF_LONG_SECTION_NAMES
2388 unsigned long string_size = 4;
2391 bfd_seek (abfd, (file_ptr) 0, 0);
2393 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2394 H_SET_MAGIC_NUMBER (h, COFF_MAGIC);
2395 H_SET_VERSION_STAMP (h, 0);
2396 H_SET_ENTRY_POINT (h, 0);
2397 H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address);
2398 H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address);
2399 H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr,
2401 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2402 H_SET_SIZEOF_OPTIONAL_HEADER (h, 0);
2403 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2405 i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer);
2407 bfd_bwrite (buffer, (bfd_size_type) i, abfd);
2408 bfd_bwrite (buffero, (bfd_size_type) H_GET_SIZEOF_OPTIONAL_HEADER (h), abfd);
2410 for (i = SEG_E0; i < SEG_LAST; i++)
2412 if (segment_info[i].scnhdr.s_name[0])
2416 #ifdef COFF_LONG_SECTION_NAMES
2417 /* Support long section names as found in PE. This code
2418 must coordinate with that in write_object_file and
2420 if (strlen (segment_info[i].name) > SCNNMLEN)
2422 memset (segment_info[i].scnhdr.s_name, 0, SCNNMLEN);
2423 sprintf (segment_info[i].scnhdr.s_name, "/%lu", string_size);
2424 string_size += strlen (segment_info[i].name) + 1;
2427 size = bfd_coff_swap_scnhdr_out (abfd,
2428 &(segment_info[i].scnhdr),
2431 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2432 bfd_bwrite (buffer, (bfd_size_type) size, abfd);
2438 symbol_to_chars (abfd, where, symbolP)
2443 unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
2447 /* Turn any symbols with register attributes into abs symbols. */
2448 if (S_GET_SEGMENT (symbolP) == reg_section)
2449 S_SET_SEGMENT (symbolP, absolute_section);
2451 /* At the same time, relocate all symbols to their output value. */
2453 val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr
2454 + S_GET_VALUE (symbolP));
2456 val = S_GET_VALUE (symbolP);
2459 S_SET_VALUE (symbolP, val);
2461 symbolP->sy_symbol.ost_entry.n_value = val;
2463 where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry,
2466 for (i = 0; i < numaux; i++)
2468 where += bfd_coff_swap_aux_out (abfd,
2469 &symbolP->sy_symbol.ost_auxent[i],
2470 S_GET_DATA_TYPE (symbolP),
2471 S_GET_STORAGE_CLASS (symbolP),
2479 coff_obj_symbol_new_hook (symbolP)
2482 char underscore = 0; /* Symbol has leading _ */
2484 /* Effective symbol. */
2485 /* Store the pointer in the offset. */
2486 S_SET_ZEROES (symbolP, 0L);
2487 S_SET_DATA_TYPE (symbolP, T_NULL);
2488 S_SET_STORAGE_CLASS (symbolP, 0);
2489 S_SET_NUMBER_AUXILIARY (symbolP, 0);
2490 /* Additional information. */
2491 symbolP->sy_symbol.ost_flags = 0;
2492 /* Auxiliary entries. */
2493 memset ((char *) &symbolP->sy_symbol.ost_auxent[0], 0, AUXESZ);
2495 if (S_IS_STRING (symbolP))
2496 SF_SET_STRING (symbolP);
2497 if (!underscore && S_IS_LOCAL (symbolP))
2498 SF_SET_LOCAL (symbolP);
2501 /* Handle .ln directives. */
2504 obj_coff_ln (appline)
2509 if (! appline && def_symbol_in_progress != NULL)
2511 /* Wrong context. */
2512 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2513 demand_empty_rest_of_line ();
2517 l = get_absolute_expression ();
2518 c_line_new (0, frag_now_fix (), l, frag_now);
2521 new_logical_line ((char *) NULL, l - 1);
2531 listing_source_line ((unsigned int) l);
2536 demand_empty_rest_of_line ();
2539 /* Handle .def directives.
2541 One might ask : why can't we symbol_new if the symbol does not
2542 already exist and fill it with debug information. Because of
2543 the C_EFCN special symbol. It would clobber the value of the
2544 function symbol before we have a chance to notice that it is
2545 a C_EFCN. And a second reason is that the code is more clear this
2546 way. (at least I think it is :-). */
2548 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2549 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2550 *input_line_pointer == '\t') \
2551 input_line_pointer++;
2555 int what ATTRIBUTE_UNUSED;
2557 char name_end; /* Char after the end of name. */
2558 char *symbol_name; /* Name of the debug symbol. */
2559 char *symbol_name_copy; /* Temporary copy of the name. */
2560 unsigned int symbol_name_length;
2562 if (def_symbol_in_progress != NULL)
2564 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2565 demand_empty_rest_of_line ();
2569 SKIP_WHITESPACES ();
2571 def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress));
2572 memset (def_symbol_in_progress, 0, sizeof (*def_symbol_in_progress));
2574 symbol_name = input_line_pointer;
2575 name_end = get_symbol_end ();
2576 symbol_name_length = strlen (symbol_name);
2577 symbol_name_copy = xmalloc (symbol_name_length + 1);
2578 strcpy (symbol_name_copy, symbol_name);
2579 #ifdef tc_canonicalize_symbol_name
2580 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
2583 /* Initialize the new symbol. */
2584 #ifdef STRIP_UNDERSCORE
2585 S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_'
2586 ? symbol_name_copy + 1
2587 : symbol_name_copy));
2588 #else /* STRIP_UNDERSCORE */
2589 S_SET_NAME (def_symbol_in_progress, symbol_name_copy);
2590 #endif /* STRIP_UNDERSCORE */
2591 /* free(symbol_name_copy); */
2592 def_symbol_in_progress->sy_name_offset = (unsigned long) ~0;
2593 def_symbol_in_progress->sy_number = ~0;
2594 def_symbol_in_progress->sy_frag = &zero_address_frag;
2595 S_SET_VALUE (def_symbol_in_progress, 0);
2597 if (S_IS_STRING (def_symbol_in_progress))
2598 SF_SET_STRING (def_symbol_in_progress);
2600 *input_line_pointer = name_end;
2602 demand_empty_rest_of_line ();
2605 unsigned int dim_index;
2608 obj_coff_endef (ignore)
2609 int ignore ATTRIBUTE_UNUSED;
2611 symbolS *symbolP = 0;
2614 if (def_symbol_in_progress == NULL)
2616 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2617 demand_empty_rest_of_line ();
2621 /* Set the section number according to storage class. */
2622 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
2627 SF_SET_TAG (def_symbol_in_progress);
2628 /* Intentional fallthrough. */
2632 SF_SET_DEBUG (def_symbol_in_progress);
2633 S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG);
2637 /* Do not emit this symbol. */
2638 SF_SET_LOCAL (def_symbol_in_progress);
2639 /* Intentional fallthrough. */
2642 /* Will need processing before writing. */
2643 SF_SET_PROCESS (def_symbol_in_progress);
2644 /* Intentional fallthrough. */
2647 S_SET_SEGMENT (def_symbol_in_progress, SEG_E0);
2649 if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0)
2651 if (function_lineoff < 0)
2652 fprintf (stderr, _("`.bf' symbol without preceding function\n"));
2654 SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff;
2656 SF_SET_PROCESS (last_line_symbol);
2657 SF_SET_ADJ_LNNOPTR (last_line_symbol);
2658 SF_SET_PROCESS (def_symbol_in_progress);
2659 function_lineoff = -1;
2662 /* Value is always set to . */
2663 def_symbol_in_progress->sy_frag = frag_now;
2664 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2669 #endif /* C_AUTOARG */
2679 SF_SET_DEBUG (def_symbol_in_progress);
2680 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
2690 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
2696 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress));
2700 /* Now that we have built a debug symbol, try to find if we should
2701 merge with an existing symbol or not. If a symbol is C_EFCN or
2702 absolute_section or untagged SEG_DEBUG it never merges. We also
2703 don't merge labels, which are in a different namespace, nor
2704 symbols which have not yet been defined since they are typically
2705 unique, nor do we merge tags with non-tags. */
2707 /* Two cases for functions. Either debug followed by definition or
2708 definition followed by debug. For definition first, we will
2709 merge the debug symbol into the definition. For debug first, the
2710 lineno entry MUST point to the definition function or else it
2711 will point off into space when crawl_symbols() merges the debug
2712 symbol into the real symbol. Therefor, let's presume the debug
2713 symbol is a real function reference. */
2715 /* FIXME-SOON If for some reason the definition label/symbol is
2716 never seen, this will probably leave an undefined symbol at link
2719 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
2720 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
2721 || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG
2722 && !SF_GET_TAG (def_symbol_in_progress))
2723 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
2724 || def_symbol_in_progress->sy_value.X_op != O_constant
2725 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL
2726 || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)))
2728 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
2733 /* This symbol already exists, merge the newly created symbol
2734 into the old one. This is not mandatory. The linker can
2735 handle duplicate symbols correctly. But I guess that it save
2736 a *lot* of space if the assembly file defines a lot of
2739 /* The debug entry (def_symbol_in_progress) is merged into the
2740 previous definition. */
2742 c_symbol_merge (def_symbol_in_progress, symbolP);
2743 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2744 def_symbol_in_progress = symbolP;
2746 if (SF_GET_FUNCTION (def_symbol_in_progress)
2747 || SF_GET_TAG (def_symbol_in_progress)
2748 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
2750 /* For functions, and tags, and static symbols, the symbol
2751 *must* be where the debug symbol appears. Move the
2752 existing symbol to the current place. */
2753 /* If it already is at the end of the symbol list, do nothing. */
2754 if (def_symbol_in_progress != symbol_lastP)
2756 symbol_remove (def_symbol_in_progress, &symbol_rootP,
2758 symbol_append (def_symbol_in_progress, symbol_lastP,
2759 &symbol_rootP, &symbol_lastP);
2764 if (SF_GET_TAG (def_symbol_in_progress))
2768 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
2770 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
2771 tag_insert (S_GET_NAME (def_symbol_in_progress),
2772 def_symbol_in_progress);
2775 if (SF_GET_FUNCTION (def_symbol_in_progress))
2777 know (sizeof (def_symbol_in_progress) <= sizeof (long));
2779 = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag);
2781 SF_SET_PROCESS (def_symbol_in_progress);
2783 if (symbolP == NULL)
2785 /* That is, if this is the first time we've seen the
2787 symbol_table_insert (def_symbol_in_progress);
2791 def_symbol_in_progress = NULL;
2792 demand_empty_rest_of_line ();
2796 obj_coff_dim (ignore)
2797 int ignore ATTRIBUTE_UNUSED;
2801 if (def_symbol_in_progress == NULL)
2803 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2804 demand_empty_rest_of_line ();
2808 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2810 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
2812 SKIP_WHITESPACES ();
2813 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
2814 get_absolute_expression ());
2816 switch (*input_line_pointer)
2819 input_line_pointer++;
2823 as_warn (_("badly formed .dim directive ignored"));
2824 /* Intentional fallthrough. */
2833 demand_empty_rest_of_line ();
2837 obj_coff_line (ignore)
2838 int ignore ATTRIBUTE_UNUSED;
2843 if (def_symbol_in_progress == NULL)
2849 name = S_GET_NAME (def_symbol_in_progress);
2850 this_base = get_absolute_expression ();
2852 /* Only .bf symbols indicate the use of a new base line number; the
2853 line numbers associated with .ef, .bb, .eb are relative to the
2854 start of the containing function. */
2855 if (!strcmp (".bf", name))
2857 #if 0 /* XXX Can we ever have line numbers going backwards? */
2858 if (this_base > line_base)
2860 line_base = this_base;
2866 listing_source_line ((unsigned int) line_base);
2871 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2872 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
2874 demand_empty_rest_of_line ();
2878 obj_coff_size (ignore)
2879 int ignore ATTRIBUTE_UNUSED;
2881 if (def_symbol_in_progress == NULL)
2883 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2884 demand_empty_rest_of_line ();
2888 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2889 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
2890 demand_empty_rest_of_line ();
2894 obj_coff_scl (ignore)
2895 int ignore ATTRIBUTE_UNUSED;
2897 if (def_symbol_in_progress == NULL)
2899 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2900 demand_empty_rest_of_line ();
2904 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
2905 demand_empty_rest_of_line ();
2909 obj_coff_tag (ignore)
2910 int ignore ATTRIBUTE_UNUSED;
2915 if (def_symbol_in_progress == NULL)
2917 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2918 demand_empty_rest_of_line ();
2922 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2923 symbol_name = input_line_pointer;
2924 name_end = get_symbol_end ();
2925 #ifdef tc_canonicalize_symbol_name
2926 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2929 /* Assume that the symbol referred to by .tag is always defined.
2930 This was a bad assumption. I've added find_or_make. xoxorich. */
2931 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
2932 (long) tag_find_or_make (symbol_name));
2933 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
2934 as_warn (_("tag not found for .tag %s"), symbol_name);
2936 SF_SET_TAGGED (def_symbol_in_progress);
2937 *input_line_pointer = name_end;
2939 demand_empty_rest_of_line ();
2943 obj_coff_type (ignore)
2944 int ignore ATTRIBUTE_UNUSED;
2946 if (def_symbol_in_progress == NULL)
2948 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2949 demand_empty_rest_of_line ();
2953 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
2955 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
2956 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
2957 SF_SET_FUNCTION (def_symbol_in_progress);
2959 demand_empty_rest_of_line ();
2963 obj_coff_val (ignore)
2964 int ignore ATTRIBUTE_UNUSED;
2966 if (def_symbol_in_progress == NULL)
2968 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2969 demand_empty_rest_of_line ();
2973 if (is_name_beginner (*input_line_pointer))
2975 char *symbol_name = input_line_pointer;
2976 char name_end = get_symbol_end ();
2978 #ifdef tc_canonicalize_symbol_name
2979 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2982 if (!strcmp (symbol_name, "."))
2984 def_symbol_in_progress->sy_frag = frag_now;
2985 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2986 /* If the .val is != from the .def (e.g. statics). */
2988 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
2990 def_symbol_in_progress->sy_value.X_op = O_symbol;
2991 def_symbol_in_progress->sy_value.X_add_symbol =
2992 symbol_find_or_make (symbol_name);
2993 def_symbol_in_progress->sy_value.X_op_symbol = NULL;
2994 def_symbol_in_progress->sy_value.X_add_number = 0;
2996 /* If the segment is undefined when the forward reference is
2997 resolved, then copy the segment id from the forward
2999 SF_SET_GET_SEGMENT (def_symbol_in_progress);
3001 /* FIXME: gcc can generate address expressions here in
3002 unusual cases (search for "obscure" in sdbout.c). We
3003 just ignore the offset here, thus generating incorrect
3004 debugging information. We ignore the rest of the line
3007 /* Otherwise, it is the name of a non debug symbol and
3008 its value will be calculated later. */
3009 *input_line_pointer = name_end;
3011 /* FIXME: this is to avoid an error message in the
3012 FIXME case mentioned just above. */
3013 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3014 ++input_line_pointer;
3018 S_SET_VALUE (def_symbol_in_progress,
3019 (valueT) get_absolute_expression ());
3020 } /* if symbol based */
3022 demand_empty_rest_of_line ();
3027 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
3028 read.c, which then calls this object file format specific routine. */
3031 obj_coff_pe_handle_link_once (type)
3032 enum linkonce_type type;
3034 seg_info (now_seg)->scnhdr.s_flags |= IMAGE_SCN_LNK_COMDAT;
3036 /* We store the type in the seg_info structure, and use it to set up
3037 the auxiliary entry for the section symbol in c_section_symbol. */
3038 seg_info (now_seg)->linkonce = type;
3044 coff_obj_read_begin_hook ()
3046 /* These had better be the same. Usually 18 bytes. */
3048 know (sizeof (SYMENT) == sizeof (AUXENT));
3049 know (SYMESZ == AUXESZ);
3054 /* This function runs through the symbol table and puts all the
3055 externals onto another chain. */
3057 /* The chain of globals. */
3058 symbolS *symbol_globalP;
3059 symbolS *symbol_global_lastP;
3061 /* The chain of externals. */
3062 symbolS *symbol_externP;
3063 symbolS *symbol_extern_lastP;
3066 symbolS *last_functionP;
3067 static symbolS *last_bfP;
3074 unsigned int symbol_number = 0;
3075 unsigned int last_file_symno = 0;
3077 struct filename_list *filename_list_scan = filename_list_head;
3079 for (symbolP = symbol_rootP;
3081 symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP)
3083 if (symbolP->sy_mri_common)
3085 if (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3087 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3089 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)
3090 as_bad (_("%s: global symbols not supported in common sections"),
3091 S_GET_NAME (symbolP));
3092 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3096 if (!SF_GET_DEBUG (symbolP))
3098 /* Debug symbols do not need all this rubbish. */
3099 symbolS *real_symbolP;
3101 /* L* and C_EFCN symbols never merge. */
3102 if (!SF_GET_LOCAL (symbolP)
3103 && !SF_GET_STATICS (symbolP)
3104 && S_GET_STORAGE_CLASS (symbolP) != C_LABEL
3105 && symbolP->sy_value.X_op == O_constant
3106 && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP))
3107 && real_symbolP != symbolP)
3109 /* FIXME-SOON: where do dups come from?
3110 Maybe tag references before definitions? xoxorich. */
3111 /* Move the debug data from the debug symbol to the
3112 real symbol. Do NOT do the opposite (i.e. move from
3113 real symbol to debug symbol and remove real symbol from the
3114 list.) Because some pointers refer to the real symbol
3115 whereas no pointers refer to the debug symbol. */
3116 c_symbol_merge (symbolP, real_symbolP);
3117 /* Replace the current symbol by the real one. */
3118 /* The symbols will never be the last or the first
3119 because : 1st symbol is .file and 3 last symbols are
3120 .text, .data, .bss. */
3121 symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP);
3122 symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP);
3123 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3124 symbolP = real_symbolP;
3127 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_E1))
3128 S_SET_SEGMENT (symbolP, SEG_E0);
3130 resolve_symbol_value (symbolP);
3132 if (S_GET_STORAGE_CLASS (symbolP) == C_NULL)
3134 if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP))
3136 S_SET_EXTERNAL (symbolP);
3139 else if (S_GET_SEGMENT (symbolP) == SEG_E0)
3140 S_SET_STORAGE_CLASS (symbolP, C_LABEL);
3143 S_SET_STORAGE_CLASS (symbolP, C_STAT);
3146 /* Mainly to speed up if not -g. */
3147 if (SF_GET_PROCESS (symbolP))
3149 /* Handle the nested blocks auxiliary info. */
3150 if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK)
3152 if (!strcmp (S_GET_NAME (symbolP), ".bb"))
3153 stack_push (block_stack, (char *) &symbolP);
3157 symbolS *begin_symbolP;
3159 begin_symbolP = *(symbolS **) stack_pop (block_stack);
3160 if (begin_symbolP == (symbolS *) 0)
3161 as_warn (_("mismatched .eb"));
3163 SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2);
3166 /* If we are able to identify the type of a function, and we
3167 are out of a function (last_functionP == 0) then, the
3168 function symbol will be associated with an auxiliary
3170 if (last_functionP == (symbolS *) 0 &&
3171 SF_GET_FUNCTION (symbolP))
3173 last_functionP = symbolP;
3175 if (S_GET_NUMBER_AUXILIARY (symbolP) < 1)
3176 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3178 /* Clobber possible stale .dim information. */
3180 /* Iffed out by steve - this fries the lnnoptr info too. */
3181 bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen,
3182 sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen));
3185 if (S_GET_STORAGE_CLASS (symbolP) == C_FCN)
3187 if (strcmp (S_GET_NAME (symbolP), ".bf") == 0)
3189 if (last_bfP != NULL)
3190 SA_SET_SYM_ENDNDX (last_bfP, symbol_number);
3194 else if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN)
3196 /* I don't even know if this is needed for sdb. But
3197 the standard assembler generates it, so... */
3198 if (last_functionP == (symbolS *) 0)
3199 as_fatal (_("C_EFCN symbol out of scope"));
3200 SA_SET_SYM_FSIZE (last_functionP,
3201 (long) (S_GET_VALUE (symbolP) -
3202 S_GET_VALUE (last_functionP)));
3203 SA_SET_SYM_ENDNDX (last_functionP, symbol_number);
3204 last_functionP = (symbolS *) 0;
3208 else if (SF_GET_TAG (symbolP))
3210 /* First descriptor of a structure must point to
3211 the first slot after the structure description. */
3212 last_tagP = symbolP;
3215 else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS)
3217 /* +2 take in account the current symbol. */
3218 SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2);
3220 else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE)
3222 /* If the filename was too long to fit in the
3223 auxent, put it in the string table. */
3224 if (SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3225 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3227 SA_SET_FILE_FNAME_OFFSET (symbolP, string_byte_count);
3228 string_byte_count += strlen (filename_list_scan->filename) + 1;
3229 filename_list_scan = filename_list_scan->next;
3231 if (S_GET_VALUE (symbolP))
3233 S_SET_VALUE (symbolP, last_file_symno);
3234 last_file_symno = symbol_number;
3238 #ifdef tc_frob_coff_symbol
3239 tc_frob_coff_symbol (symbolP);
3242 /* We must put the external symbols apart. The loader
3243 does not bomb if we do not. But the references in
3244 the endndx field for a .bb symbol are not corrected
3245 if an external symbol is removed between .bb and .be.
3246 I.e in the following case :
3247 [20] .bb endndx = 22
3250 ld will move the symbol 21 to the end of the list but
3251 endndx will still be 22 instead of 21. */
3253 if (SF_GET_LOCAL (symbolP))
3255 /* Remove C_EFCN and LOCAL (L...) symbols. */
3256 /* Next pointer remains valid. */
3257 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3260 else if (symbolP->sy_value.X_op == O_symbol
3261 && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
3263 /* Skip symbols which were equated to undefined or common
3265 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3267 else if (!S_IS_DEFINED (symbolP)
3268 && !S_IS_DEBUG (symbolP)
3269 && !SF_GET_STATICS (symbolP)
3270 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3272 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3274 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT))
3276 /* If external, Remove from the list. */
3277 symbolS *hold = symbol_previous (symbolP);
3279 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3280 symbol_clear_list_pointers (symbolP);
3281 symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP);
3284 else if (! S_IS_DEBUG (symbolP)
3285 && ! SF_GET_STATICS (symbolP)
3286 && ! SF_GET_FUNCTION (symbolP)
3287 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3289 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3291 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK))
3293 symbolS *hold = symbol_previous (symbolP);
3295 /* The O'Reilly COFF book says that defined global symbols
3296 come at the end of the symbol table, just before
3297 undefined global symbols. */
3298 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3299 symbol_clear_list_pointers (symbolP);
3300 symbol_append (symbolP, symbol_global_lastP, &symbol_globalP,
3301 &symbol_global_lastP);
3306 if (SF_GET_STRING (symbolP))
3308 symbolP->sy_name_offset = string_byte_count;
3309 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
3313 symbolP->sy_name_offset = 0;
3316 symbolP->sy_number = symbol_number;
3317 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3321 return symbol_number;
3325 glue_symbols (head, tail)
3329 unsigned int symbol_number = 0;
3331 while (*head != NULL)
3333 symbolS *tmp = *head;
3336 symbol_remove (tmp, head, tail);
3337 symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP);
3340 if (SF_GET_STRING (tmp))
3342 tmp->sy_name_offset = string_byte_count;
3343 string_byte_count += strlen (S_GET_NAME (tmp)) + 1;
3347 /* Fix "long" names. */
3348 tmp->sy_name_offset = 0;
3351 tmp->sy_number = symbol_number;
3352 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp);
3355 return symbol_number;
3361 unsigned int symbol_number = 0;
3364 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
3366 symbolP->sy_number = symbol_number;
3368 if (SF_GET_TAGGED (symbolP))
3372 ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number);
3375 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3378 return symbol_number;
3383 crawl_symbols (h, abfd)
3385 bfd *abfd ATTRIBUTE_UNUSED;
3389 /* Initialize the stack used to keep track of the matching .bb .be. */
3391 block_stack = stack_init (512, sizeof (symbolS *));
3393 /* The symbol list should be ordered according to the following sequence
3396 . debug entries for functions
3397 . fake symbols for the sections, including .text .data and .bss
3400 But this is not mandatory. The only important point is to put the
3401 undefined symbols at the end of the list. */
3403 /* Is there a .file symbol ? If not insert one at the beginning. */
3404 if (symbol_rootP == NULL
3405 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
3406 c_dot_file_symbol ("fake", 0);
3408 /* Build up static symbols for the sections, they are filled in later. */
3410 for (i = SEG_E0; i < SEG_LAST; i++)
3411 if (segment_info[i].scnhdr.s_name[0])
3412 segment_info[i].dot = c_section_symbol ((char *) segment_info[i].name,
3415 /* Take all the externals out and put them into another chain. */
3416 H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ());
3417 /* Take the externals and glue them onto the end. */
3418 H_SET_SYMBOL_TABLE_SIZE (h,
3419 (H_GET_SYMBOL_COUNT (h)
3420 + glue_symbols (&symbol_globalP,
3421 &symbol_global_lastP)
3422 + glue_symbols (&symbol_externP,
3423 &symbol_extern_lastP)));
3425 H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ());
3426 know (symbol_globalP == NULL);
3427 know (symbol_global_lastP == NULL);
3428 know (symbol_externP == NULL);
3429 know (symbol_extern_lastP == NULL);
3432 /* Find strings by crawling along symbol table chain. */
3439 struct filename_list *filename_list_scan = filename_list_head;
3441 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK. */
3442 md_number_to_chars (where, (valueT) string_byte_count, 4);
3445 #ifdef COFF_LONG_SECTION_NAMES
3446 /* Support long section names as found in PE. This code must
3447 coordinate with that in coff_header_append and write_object_file. */
3451 for (i = SEG_E0; i < SEG_LAST; i++)
3453 if (segment_info[i].scnhdr.s_name[0]
3454 && strlen (segment_info[i].name) > SCNNMLEN)
3458 size = strlen (segment_info[i].name) + 1;
3459 memcpy (where, segment_info[i].name, size);
3464 #endif /* COFF_LONG_SECTION_NAMES */
3466 for (symbolP = symbol_rootP;
3468 symbolP = symbol_next (symbolP))
3472 if (SF_GET_STRING (symbolP))
3474 size = strlen (S_GET_NAME (symbolP)) + 1;
3475 memcpy (where, S_GET_NAME (symbolP), size);
3478 if (S_GET_STORAGE_CLASS (symbolP) == C_FILE
3479 && SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3480 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3482 size = strlen (filename_list_scan->filename) + 1;
3483 memcpy (where, filename_list_scan->filename, size);
3484 filename_list_scan = filename_list_scan ->next;
3491 do_linenos_for (abfd, h, file_cursor)
3494 unsigned long *file_cursor;
3497 unsigned long start = *file_cursor;
3499 for (idx = SEG_E0; idx < SEG_LAST; idx++)
3501 segment_info_type *s = segment_info + idx;
3503 if (s->scnhdr.s_nlnno != 0)
3505 struct lineno_list *line_ptr;
3507 struct external_lineno *buffer =
3508 (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ);
3510 struct external_lineno *dst = buffer;
3512 /* Run through the table we've built and turn it into its external
3513 form, take this chance to remove duplicates. */
3515 for (line_ptr = s->lineno_list_head;
3516 line_ptr != (struct lineno_list *) NULL;
3517 line_ptr = line_ptr->next)
3519 if (line_ptr->line.l_lnno == 0)
3521 /* Turn a pointer to a symbol into the symbols' index,
3522 provided that it has been initialised. */
3523 if (line_ptr->line.l_addr.l_symndx)
3524 line_ptr->line.l_addr.l_symndx =
3525 ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number;
3528 line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address;
3530 (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst);
3534 s->scnhdr.s_lnnoptr = *file_cursor;
3536 bfd_bwrite (buffer, (bfd_size_type) s->scnhdr.s_nlnno * LINESZ, abfd);
3539 *file_cursor += s->scnhdr.s_nlnno * LINESZ;
3543 H_SET_LINENO_SIZE (h, *file_cursor - start);
3546 /* Now we run through the list of frag chains in a segment and
3547 make all the subsegment frags appear at the end of the
3548 list, as if the seg 0 was extra long. */
3555 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3557 frchainS *head = segment_info[i].frchainP;
3559 fragS *prev_frag = &dummy;
3561 while (head && head->frch_seg == i)
3563 prev_frag->fr_next = head->frch_root;
3564 prev_frag = head->frch_last;
3565 head = head->frch_next;
3567 prev_frag->fr_next = 0;
3571 unsigned long machine;
3574 #ifndef SUB_SEGMENT_ALIGN
3576 /* The last subsegment gets an alignment corresponding to the alignment
3577 of the section. This allows proper nop-filling at the end of
3578 code-bearing sections. */
3579 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
3580 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \
3581 ? get_recorded_alignment (SEG) : 0)
3583 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 1
3588 write_object_file ()
3592 struct frchain *frchain_ptr;
3594 object_headers headers;
3595 unsigned long file_cursor;
3598 abfd = bfd_openw (out_file_name, TARGET_FORMAT);
3602 as_perror (_("FATAL: Can't create %s"), out_file_name);
3603 exit (EXIT_FAILURE);
3605 bfd_set_format (abfd, bfd_object);
3606 bfd_set_arch_mach (abfd, BFD_ARCH, machine);
3608 string_byte_count = 4;
3610 /* Run through all the sub-segments and align them up. Also
3611 close any open frags. We tack a .fill onto the end of the
3612 frag chain so that any .align's size can be worked by looking
3613 at the next frag. */
3614 for (frchain_ptr = frchain_root;
3615 frchain_ptr != (struct frchain *) NULL;
3616 frchain_ptr = frchain_ptr->frch_next)
3620 subseg_set (frchain_ptr->frch_seg, frchain_ptr->frch_subseg);
3622 alignment = SUB_SEGMENT_ALIGN (now_seg, frchain_ptr);
3625 md_do_align (alignment, (char *) NULL, 0, 0, alignment_done);
3627 if (subseg_text_p (now_seg))
3628 frag_align_code (alignment, 0);
3630 frag_align (alignment, 0, 0);
3636 frag_wane (frag_now);
3637 frag_now->fr_fix = 0;
3638 know (frag_now->fr_next == NULL);
3643 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3644 relax_segment (segment_info[i].frchainP->frch_root, i);
3646 /* Relaxation has completed. Freeze all syms. */
3649 H_SET_NUMBER_OF_SECTIONS (&headers, 0);
3651 /* Find out how big the sections are, and set the addresses. */
3653 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3657 segment_info[i].scnhdr.s_paddr = addr;
3658 segment_info[i].scnhdr.s_vaddr = addr;
3660 if (segment_info[i].scnhdr.s_name[0])
3662 H_SET_NUMBER_OF_SECTIONS (&headers,
3663 H_GET_NUMBER_OF_SECTIONS (&headers) + 1);
3665 #ifdef COFF_LONG_SECTION_NAMES
3666 /* Support long section names as found in PE. This code
3667 must coordinate with that in coff_header_append and
3672 len = strlen (segment_info[i].name);
3674 string_byte_count += len + 1;
3676 #endif /* COFF_LONG_SECTION_NAMES */
3679 size = size_section (abfd, (unsigned int) i);
3682 /* I think the section alignment is only used on the i960; the
3683 i960 needs it, and it should do no harm on other targets. */
3684 #ifdef ALIGNMENT_IN_S_FLAGS
3685 segment_info[i].scnhdr.s_flags |= (section_alignment[i] & 0xF) << 8;
3687 segment_info[i].scnhdr.s_align = 1 << section_alignment[i];
3691 H_SET_TEXT_SIZE (&headers, size);
3692 else if (i == SEG_E1)
3693 H_SET_DATA_SIZE (&headers, size);
3694 else if (i == SEG_E2)
3695 H_SET_BSS_SIZE (&headers, size);
3698 /* Turn the gas native symbol table shape into a coff symbol table. */
3699 crawl_symbols (&headers, abfd);
3701 if (string_byte_count == 4)
3702 string_byte_count = 0;
3704 H_SET_STRING_SIZE (&headers, string_byte_count);
3710 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3712 fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i);
3713 fixup_segment (&segment_info[i], i);
3716 /* Look for ".stab" segments and fill in their initial symbols
3718 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3720 name = segment_info[i].name;
3723 && strncmp (".stab", name, 5) == 0
3724 && strncmp (".stabstr", name, 8) != 0)
3725 adjust_stab_section (abfd, i);
3728 file_cursor = H_GET_TEXT_FILE_OFFSET (&headers);
3730 bfd_seek (abfd, (file_ptr) file_cursor, 0);
3732 /* Plant the data. */
3733 fill_section (abfd, &headers, &file_cursor);
3735 do_relocs_for (abfd, &headers, &file_cursor);
3737 do_linenos_for (abfd, &headers, &file_cursor);
3739 H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC);
3740 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3741 H_SET_TIME_STAMP (&headers, (long)time((time_t *)0));
3743 H_SET_TIME_STAMP (&headers, 0);
3745 #ifdef TC_COFF_SET_MACHINE
3746 TC_COFF_SET_MACHINE (&headers);
3750 #define COFF_FLAGS 0
3753 #ifdef KEEP_RELOC_INFO
3754 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3755 COFF_FLAGS | coff_flags));
3757 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3758 (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) |
3759 COFF_FLAGS | coff_flags));
3763 unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers);
3764 char *buffer1 = xmalloc (symtable_size + string_byte_count + 1);
3766 H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd));
3767 w_symbols (abfd, buffer1, symbol_rootP);
3768 if (string_byte_count > 0)
3769 w_strings (buffer1 + symtable_size);
3770 bfd_bwrite (buffer1, (bfd_size_type) symtable_size + string_byte_count,
3775 coff_header_append (abfd, &headers);
3777 /* Recent changes to write need this, but where it should
3778 go is up to Ken.. */
3779 if (!bfd_close_all_done (abfd))
3780 as_fatal (_("Can't close %s: %s"), out_file_name,
3781 bfd_errmsg (bfd_get_error ()));
3784 extern bfd *stdoutput;
3791 /* Add a new segment. This is called from subseg_new via the
3792 obj_new_segment macro. */
3795 obj_coff_add_segment (name)
3800 #ifndef COFF_LONG_SECTION_NAMES
3801 char buf[SCNNMLEN + 1];
3803 strncpy (buf, name, SCNNMLEN);
3804 buf[SCNNMLEN] = '\0';
3808 for (i = SEG_E0; i < SEG_LAST && segment_info[i].scnhdr.s_name[0]; i++)
3809 if (strcmp (name, segment_info[i].name) == 0)
3814 as_bad (_("Too many new sections; can't add \"%s\""), name);
3818 /* Add a new section. */
3819 strncpy (segment_info[i].scnhdr.s_name, name,
3820 sizeof (segment_info[i].scnhdr.s_name));
3821 segment_info[i].scnhdr.s_flags = STYP_REG;
3822 segment_info[i].name = xstrdup (name);
3827 /* Implement the .section pseudo op:
3828 .section name {, "flags"}
3830 | +--- optional flags: 'b' for bss
3832 +-- section name 'l' for lib
3836 'd' (apparently m88k for data)
3838 'r' for read-only data
3839 But if the argument is not a quoted string, treat it as a
3840 subsegment number. */
3843 obj_coff_section (ignore)
3844 int ignore ATTRIBUTE_UNUSED;
3846 /* Strip out the section name. */
3847 char *section_name, *name;
3860 else if (type == 'D')
3862 segment_info[now_seg].scnhdr.s_flags |= flags;
3867 section_name = input_line_pointer;
3868 c = get_symbol_end ();
3870 name = xmalloc (input_line_pointer - section_name + 1);
3871 strcpy (name, section_name);
3873 *input_line_pointer = c;
3879 if (*input_line_pointer == ',')
3881 ++input_line_pointer;
3884 if (*input_line_pointer != '"')
3885 exp = get_absolute_expression ();
3888 ++input_line_pointer;
3889 while (*input_line_pointer != '"'
3890 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3892 switch (*input_line_pointer)
3894 case 'b': flags |= STYP_BSS; break;
3895 case 'i': flags |= STYP_INFO; break;
3896 case 'l': flags |= STYP_LIB; break;
3897 case 'n': flags |= STYP_NOLOAD; break;
3898 case 'o': flags |= STYP_OVER; break;
3900 case 'w': flags |= STYP_DATA; break;
3901 case 'x': flags |= STYP_TEXT; break;
3902 case 'r': flags |= STYP_LIT; break;
3904 as_warn(_("unknown section attribute '%c'"),
3905 *input_line_pointer);
3908 ++input_line_pointer;
3910 if (*input_line_pointer == '"')
3911 ++input_line_pointer;
3915 subseg_new (name, (subsegT) exp);
3917 segment_info[now_seg].scnhdr.s_flags |= flags;
3919 demand_empty_rest_of_line ();
3923 obj_coff_text (ignore)
3924 int ignore ATTRIBUTE_UNUSED;
3926 subseg_new (".text", get_absolute_expression ());
3930 obj_coff_data (ignore)
3931 int ignore ATTRIBUTE_UNUSED;
3933 if (flag_readonly_data_in_text)
3934 subseg_new (".text", get_absolute_expression () + 1000);
3936 subseg_new (".data", get_absolute_expression ());
3940 obj_coff_ident (ignore)
3941 int ignore ATTRIBUTE_UNUSED;
3943 segT current_seg = now_seg; /* Save current seg. */
3944 subsegT current_subseg = now_subseg;
3946 subseg_new (".comment", 0); /* .comment seg. */
3947 stringer (1); /* Read string. */
3948 subseg_set (current_seg, current_subseg); /* Restore current seg. */
3952 c_symbol_merge (debug, normal)
3956 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
3957 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
3959 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
3960 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
3962 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
3963 memcpy ((char *) &normal->sy_symbol.ost_auxent[0],
3964 (char *) &debug->sy_symbol.ost_auxent[0],
3965 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug) * AUXESZ));
3967 /* Move the debug flags. */
3968 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
3972 c_line_new (symbol, paddr, line_number, frag)
3978 struct lineno_list *new_line =
3979 (struct lineno_list *) xmalloc (sizeof (struct lineno_list));
3981 segment_info_type *s = segment_info + now_seg;
3982 new_line->line.l_lnno = line_number;
3984 if (line_number == 0)
3986 last_line_symbol = symbol;
3987 new_line->line.l_addr.l_symndx = (long) symbol;
3991 new_line->line.l_addr.l_paddr = paddr;
3994 new_line->frag = (char *) frag;
3995 new_line->next = (struct lineno_list *) NULL;
3997 if (s->lineno_list_head == (struct lineno_list *) NULL)
3998 s->lineno_list_head = new_line;
4000 s->lineno_list_tail->next = new_line;
4002 s->lineno_list_tail = new_line;
4003 return LINESZ * s->scnhdr.s_nlnno++;
4007 c_dot_file_symbol (const char *filename, int appfile ATTRIBUTE_UNUSED)
4011 symbolP = symbol_new (".file",
4014 &zero_address_frag);
4016 S_SET_STORAGE_CLASS (symbolP, C_FILE);
4017 S_SET_NUMBER_AUXILIARY (symbolP, 1);
4019 if (strlen (filename) > FILNMLEN)
4021 /* Filename is too long to fit into an auxent,
4022 we stick it into the string table instead. We keep
4023 a linked list of the filenames we find so we can emit
4025 struct filename_list *f = ((struct filename_list *)
4026 xmalloc (sizeof (struct filename_list)));
4028 f->filename = filename;
4031 SA_SET_FILE_FNAME_ZEROS (symbolP, 0);
4032 SA_SET_FILE_FNAME_OFFSET (symbolP, 1);
4034 if (filename_list_tail)
4035 filename_list_tail->next = f;
4037 filename_list_head = f;
4038 filename_list_tail = f;
4042 SA_SET_FILE_FNAME (symbolP, filename);
4048 listing_source_file (filename);
4051 SF_SET_DEBUG (symbolP);
4052 S_SET_VALUE (symbolP, (valueT) previous_file_symbol);
4054 previous_file_symbol = symbolP;
4056 /* Make sure that the symbol is first on the symbol chain. */
4057 if (symbol_rootP != symbolP)
4059 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
4060 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
4064 /* Build a 'section static' symbol. */
4067 c_section_symbol (name, idx)
4073 symbolP = symbol_find_base (name, DO_NOT_STRIP);
4074 if (symbolP == NULL)
4075 symbolP = symbol_new (name, idx, 0, &zero_address_frag);
4078 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
4079 S_SET_SEGMENT (symbolP, idx);
4080 symbolP->sy_frag = &zero_address_frag;
4083 S_SET_STORAGE_CLASS (symbolP, C_STAT);
4084 S_SET_NUMBER_AUXILIARY (symbolP, 1);
4086 SF_SET_STATICS (symbolP);
4090 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
4091 SF_CLEAR_LOCAL (symbolP);
4094 /* If the .linkonce pseudo-op was used for this section, we must
4095 store the information in the auxiliary entry for the section
4097 if (segment_info[idx].linkonce != LINKONCE_UNSET)
4101 switch (segment_info[idx].linkonce)
4105 case LINKONCE_DISCARD:
4106 type = IMAGE_COMDAT_SELECT_ANY;
4108 case LINKONCE_ONE_ONLY:
4109 type = IMAGE_COMDAT_SELECT_NODUPLICATES;
4111 case LINKONCE_SAME_SIZE:
4112 type = IMAGE_COMDAT_SELECT_SAME_SIZE;
4114 case LINKONCE_SAME_CONTENTS:
4115 type = IMAGE_COMDAT_SELECT_EXACT_MATCH;
4119 SYM_AUXENT (symbolP)->x_scn.x_comdat = type;
4127 w_symbols (abfd, where, symbol_rootP)
4130 symbolS * symbol_rootP;
4135 /* First fill in those values we have only just worked out. */
4136 for (i = SEG_E0; i < SEG_LAST; i++)
4138 symbolP = segment_info[i].dot;
4141 SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size);
4142 SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc);
4143 SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno);
4147 /* Emit all symbols left in the symbol chain. */
4148 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
4150 /* Used to save the offset of the name. It is used to point
4151 to the string in memory but must be a file offset. */
4154 /* We can't fix the lnnoptr field in yank_symbols with the other
4155 adjustments, because we have to wait until we know where they
4157 if (SF_GET_ADJ_LNNOPTR (symbolP))
4158 SA_GET_SYM_LNNOPTR (symbolP) +=
4159 segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_lnnoptr;
4161 tc_coff_symbol_emit_hook (symbolP);
4163 temp = S_GET_NAME (symbolP);
4164 if (SF_GET_STRING (symbolP))
4166 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
4167 S_SET_ZEROES (symbolP, 0);
4171 memset (symbolP->sy_symbol.ost_entry.n_name, 0, SYMNMLEN);
4172 strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
4174 where = symbol_to_chars (abfd, where, symbolP);
4175 S_SET_NAME (symbolP, temp);
4180 obj_coff_lcomm (ignore)
4181 int ignore ATTRIBUTE_UNUSED;
4193 name = input_line_pointer;
4195 c = get_symbol_end ();
4196 p = input_line_pointer;
4199 if (*input_line_pointer != ',')
4201 as_bad (_("Expected comma after name"));
4202 ignore_rest_of_line ();
4205 if (*input_line_pointer == '\n')
4207 as_bad (_("Missing size expression"));
4210 input_line_pointer++;
4211 if ((temp = get_absolute_expression ()) < 0)
4213 as_warn (_("lcomm length (%d.) <0! Ignored."), temp);
4214 ignore_rest_of_line ();
4219 symbolP = symbol_find_or_make (name);
4221 if (S_GET_SEGMENT (symbolP) == SEG_UNKNOWN &&
4222 S_GET_VALUE (symbolP) == 0)
4227 segT current_seg = now_seg; /* Save current seg. */
4228 subsegT current_subseg = now_subseg;
4230 subseg_set (SEG_E2, 1);
4231 symbolP->sy_frag = frag_now;
4232 p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP,
4233 (offsetT) temp, (char *) 0);
4235 subseg_set (current_seg, current_subseg); /* Restore current seg. */
4236 S_SET_SEGMENT (symbolP, SEG_E2);
4237 S_SET_STORAGE_CLASS (symbolP, C_STAT);
4241 as_bad (_("Symbol %s already defined"), name);
4243 demand_empty_rest_of_line ();
4248 fixup_mdeps (frags, h, this_segment)
4250 object_headers *h ATTRIBUTE_UNUSED;
4253 subseg_change (this_segment, 0);
4257 switch (frags->fr_type)
4264 HANDLE_ALIGN (frags);
4266 frags->fr_type = rs_fill;
4268 ((frags->fr_next->fr_address - frags->fr_address - frags->fr_fix)
4271 case rs_machine_dependent:
4272 md_convert_frag (h, this_segment, frags);
4278 frags = frags->fr_next;
4284 #ifndef TC_FORCE_RELOCATION
4285 #define TC_FORCE_RELOCATION(fix) 0
4289 fixup_segment (segP, this_segment_type)
4290 segment_info_type * segP;
4291 segT this_segment_type;
4294 symbolS *add_symbolP;
4295 symbolS *sub_symbolP;
4302 segT add_symbol_segment = absolute_section;
4304 for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next)
4306 fragP = fixP->fx_frag;
4308 where = fixP->fx_where;
4309 place = fragP->fr_literal + where;
4310 size = fixP->fx_size;
4311 add_symbolP = fixP->fx_addsy;
4312 sub_symbolP = fixP->fx_subsy;
4313 add_number = fixP->fx_offset;
4314 pcrel = fixP->fx_pcrel;
4316 /* We want function-relative stabs to work on systems which
4317 may use a relaxing linker; thus we must handle the sym1-sym2
4318 fixups function-relative stabs generates.
4320 Of course, if you actually enable relaxing in the linker, the
4321 line and block scoping information is going to be incorrect
4322 in some cases. The only way to really fix this is to support
4323 a reloc involving the difference of two symbols. */
4325 && (!sub_symbolP || pcrel))
4329 if (fixP->fx_tcbit && SF_GET_CALLNAME (add_symbolP))
4331 /* Relocation should be done via the associated 'bal' entry
4334 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP)))
4336 as_bad_where (fixP->fx_file, fixP->fx_line,
4337 _("No 'bal' entry point for leafproc %s"),
4338 S_GET_NAME (add_symbolP));
4341 fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
4345 /* Make sure the symbols have been resolved; this may not have
4346 happened if these are expression symbols. */
4347 if (add_symbolP != NULL && ! add_symbolP->sy_resolved)
4348 resolve_symbol_value (add_symbolP);
4350 if (add_symbolP != NULL)
4352 /* If this fixup is against a symbol which has been equated
4353 to another symbol, convert it to the other symbol. */
4354 if (add_symbolP->sy_value.X_op == O_symbol
4355 && (! S_IS_DEFINED (add_symbolP)
4356 || S_IS_COMMON (add_symbolP)))
4358 while (add_symbolP->sy_value.X_op == O_symbol
4359 && (! S_IS_DEFINED (add_symbolP)
4360 || S_IS_COMMON (add_symbolP)))
4364 /* We must avoid looping, as that can occur with a
4365 badly written program. */
4366 n = add_symbolP->sy_value.X_add_symbol;
4367 if (n == add_symbolP)
4369 add_number += add_symbolP->sy_value.X_add_number;
4372 fixP->fx_addsy = add_symbolP;
4373 fixP->fx_offset = add_number;
4377 if (sub_symbolP != NULL && ! sub_symbolP->sy_resolved)
4378 resolve_symbol_value (sub_symbolP);
4380 if (add_symbolP != NULL
4381 && add_symbolP->sy_mri_common)
4383 know (add_symbolP->sy_value.X_op == O_symbol);
4384 add_number += S_GET_VALUE (add_symbolP);
4385 fixP->fx_offset = add_number;
4386 add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol;
4390 add_symbol_segment = S_GET_SEGMENT (add_symbolP);
4394 if (add_symbolP == NULL || add_symbol_segment == absolute_section)
4396 if (add_symbolP != NULL)
4398 add_number += S_GET_VALUE (add_symbolP);
4400 fixP->fx_addsy = NULL;
4403 /* It's just -sym. */
4404 if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
4406 add_number -= S_GET_VALUE (sub_symbolP);
4413 as_bad_where (fixP->fx_file, fixP->fx_line,
4414 _("Negative of non-absolute symbol %s"),
4415 S_GET_NAME (sub_symbolP));
4417 add_number -= S_GET_VALUE (sub_symbolP);
4418 } /* not absolute */
4420 /* if sub_symbol is in the same segment that add_symbol
4421 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE. */
4423 else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
4424 && SEG_NORMAL (add_symbol_segment))
4426 /* Difference of 2 symbols from same segment. Can't
4427 make difference of 2 undefineds: 'value' means
4428 something different for N_UNDF. */
4430 /* Makes no sense to use the difference of 2 arbitrary symbols
4431 as the target of a call instruction. */
4433 as_bad_where (fixP->fx_file, fixP->fx_line,
4434 _("callj to difference of 2 symbols"));
4435 #endif /* TC_I960 */
4436 add_number += S_GET_VALUE (add_symbolP) -
4437 S_GET_VALUE (sub_symbolP);
4440 if (!TC_FORCE_RELOCATION (fixP))
4442 fixP->fx_addsy = NULL;
4443 fixP->fx_subsy = NULL;
4445 #ifdef TC_M68K /* is this right? */
4453 /* Different segments in subtraction. */
4454 know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
4456 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
4457 add_number -= S_GET_VALUE (sub_symbolP);
4460 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
4461 #if 0 /* Okay for 68k, at least... */
4466 /* Make it pc-relative. */
4467 add_number += (md_pcrel_from (fixP)
4468 - S_GET_VALUE (sub_symbolP));
4477 as_bad_where (fixP->fx_file, fixP->fx_line,
4478 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4479 segment_name (S_GET_SEGMENT (sub_symbolP)),
4480 S_GET_NAME (sub_symbolP),
4481 (long) (fragP->fr_address + where));
4488 if (add_symbol_segment == this_segment_type && pcrel)
4490 /* This fixup was made when the symbol's segment was
4491 SEG_UNKNOWN, but it is now in the local segment.
4492 So we know how to do the address without relocation. */
4494 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4495 in which cases it modifies *fixP as appropriate. In the case
4496 of a 'calls', no further work is required, and *fixP has been
4497 set up to make the rest of the code below a no-op. */
4499 #endif /* TC_I960 */
4501 add_number += S_GET_VALUE (add_symbolP);
4502 add_number -= md_pcrel_from (fixP);
4505 add_number -= segP->scnhdr.s_vaddr;
4506 if defined (TC_I386) || defined (TE_LYNX). I now
4507 think that was an error propagated from the case when
4508 we are going to emit the relocation. If we are not
4509 going to emit the relocation, then we just want to
4510 set add_number to the difference between the symbols.
4511 This is a case that would only arise when there is a
4512 PC relative reference from a section other than .text
4513 to a symbol defined in the same section, and the
4514 reference is not relaxed. Since jump instructions on
4515 the i386 are relaxed, this could only arise with a
4516 call instruction. */
4518 pcrel = 0; /* Lie. Don't want further pcrel processing. */
4519 if (!TC_FORCE_RELOCATION (fixP))
4521 fixP->fx_addsy = NULL;
4527 switch (add_symbol_segment)
4529 case absolute_section:
4531 /* See comment about reloc_callj() above. */
4533 #endif /* TC_I960 */
4534 add_number += S_GET_VALUE (add_symbolP);
4537 if (!TC_FORCE_RELOCATION (fixP))
4539 fixP->fx_addsy = NULL;
4545 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) || defined(TC_OR32)
4546 /* This really should be handled in the linker, but
4547 backward compatibility forbids. */
4548 add_number += S_GET_VALUE (add_symbolP);
4550 add_number += S_GET_VALUE (add_symbolP) +
4551 segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr;
4557 if ((int) fixP->fx_bit_fixP == 13)
4559 /* This is a COBR instruction. They have only a
4560 13-bit displacement and are only to be used
4561 for local branches: flag as error, don't generate
4563 as_bad_where (fixP->fx_file, fixP->fx_line,
4564 _("can't use COBR format with external label"));
4565 fixP->fx_addsy = NULL;
4569 #endif /* TC_I960 */
4570 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4571 /* 386 COFF uses a peculiar format in which the
4572 value of a common symbol is stored in the .text
4573 segment (I've checked this on SVR3.2 and SCO
4575 /* This is also true for 68k COFF on sysv machines
4576 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4577 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4579 if (S_IS_COMMON (add_symbolP))
4580 add_number += S_GET_VALUE (add_symbolP);
4590 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K) && !defined(TC_OR32)
4591 /* This adjustment is not correct on the m88k, for which the
4592 linker does all the computation. */
4593 add_number -= md_pcrel_from (fixP);
4595 if (add_symbolP == 0)
4596 fixP->fx_addsy = &abs_symbol;
4597 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4598 /* On the 386 we must adjust by the segment vaddr as well.
4601 I changed the i960 to work this way as well. This is
4602 compatible with the current GNU linker behaviour. I do
4603 not know what other i960 COFF assemblers do. This is not
4604 a common case: normally, only assembler code will contain
4605 a PC relative reloc, and only branches which do not
4606 originate in the .text section will have a non-zero
4609 I changed the m68k to work this way as well. This will
4610 break existing PC relative relocs from sections which do
4611 not start at address 0, but it will make ld -r work.
4612 Ian Taylor, 4 Oct 96. */
4614 add_number -= segP->scnhdr.s_vaddr;
4618 md_apply_fix3 (fixP, (valueT *) & add_number, this_segment_type);
4620 if (!fixP->fx_bit_fixP && ! fixP->fx_no_overflow)
4623 /* The m88k uses the offset field of the reloc to get around
4626 && ((add_number & ~0xFF)
4627 || (fixP->fx_signed && (add_number & 0x80)))
4628 && ((add_number & ~0xFF) != (-1 & ~0xFF)
4629 || (add_number & 0x80) == 0))
4631 && ((add_number & ~0xFFFF)
4632 || (fixP->fx_signed && (add_number & 0x8000)))
4633 && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF)
4634 || (add_number & 0x8000) == 0)))
4636 as_bad_where (fixP->fx_file, fixP->fx_line,
4637 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4638 (long) add_number, size,
4639 (unsigned long) (fragP->fr_address + where));
4642 #ifdef WARN_SIGNED_OVERFLOW_WORD
4643 /* Warn if a .word value is too large when treated as a
4644 signed number. We already know it is not too negative.
4645 This is to catch over-large switches generated by gcc on
4647 if (!flag_signed_overflow_ok
4649 && add_number > 0x7fff)
4650 as_bad_where (fixP->fx_file, fixP->fx_line,
4651 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4653 (unsigned long) (fragP->fr_address + where));
4661 /* The first entry in a .stab section is special. */
4664 obj_coff_init_stab_section (seg)
4670 unsigned int stroff;
4672 /* Make space for this first symbol. */
4676 as_where (&file, (unsigned int *) NULL);
4677 stabstr_name = (char *) alloca (strlen (segment_info[seg].name) + 4);
4678 strcpy (stabstr_name, segment_info[seg].name);
4679 strcat (stabstr_name, "str");
4680 stroff = get_stab_string_offset (file, stabstr_name);
4682 md_number_to_chars (p, stroff, 4);
4685 /* Fill in the counts in the first entry in a .stab section. */
4688 adjust_stab_section(abfd, seg)
4692 segT stabstrseg = SEG_UNKNOWN;
4693 const char *secname, *name2;
4696 int i, strsz = 0, nsyms;
4697 fragS *frag = segment_info[seg].frchainP->frch_root;
4699 /* Look for the associated string table section. */
4701 secname = segment_info[seg].name;
4702 name = (char *) alloca (strlen (secname) + 4);
4703 strcpy (name, secname);
4704 strcat (name, "str");
4706 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
4708 name2 = segment_info[i].name;
4709 if (name2 != NULL && strncmp(name2, name, 8) == 0)
4716 /* If we found the section, get its size. */
4717 if (stabstrseg != SEG_UNKNOWN)
4718 strsz = size_section (abfd, stabstrseg);
4720 nsyms = size_section (abfd, seg) / 12 - 1;
4722 /* Look for the first frag of sufficient size for the initial stab
4723 symbol, and collect a pointer to it. */
4724 while (frag && frag->fr_fix < 12)
4725 frag = frag->fr_next;
4727 p = frag->fr_literal;
4730 /* Write in the number of stab symbols and the size of the string
4732 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
4733 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
4736 #endif /* not BFD_ASSEMBLER */
4738 const pseudo_typeS coff_pseudo_table[] =
4740 {"def", obj_coff_def, 0},
4741 {"dim", obj_coff_dim, 0},
4742 {"endef", obj_coff_endef, 0},
4743 {"line", obj_coff_line, 0},
4744 {"ln", obj_coff_ln, 0},
4745 #ifdef BFD_ASSEMBLER
4746 {"loc", obj_coff_loc, 0},
4748 {"appline", obj_coff_ln, 1},
4749 {"scl", obj_coff_scl, 0},
4750 {"size", obj_coff_size, 0},
4751 {"tag", obj_coff_tag, 0},
4752 {"type", obj_coff_type, 0},
4753 {"val", obj_coff_val, 0},
4754 {"section", obj_coff_section, 0},
4755 {"sect", obj_coff_section, 0},
4756 /* FIXME: We ignore the MRI short attribute. */
4757 {"section.s", obj_coff_section, 0},
4758 {"sect.s", obj_coff_section, 0},
4759 /* We accept the .bss directive for backward compatibility with
4760 earlier versions of gas. */
4761 {"bss", obj_coff_bss, 0},
4762 {"ident", obj_coff_ident, 0},
4763 #ifndef BFD_ASSEMBLER
4764 {"use", obj_coff_section, 0},
4765 {"text", obj_coff_text, 0},
4766 {"data", obj_coff_data, 0},
4767 {"lcomm", obj_coff_lcomm, 0},
4769 {"weak", obj_coff_weak, 0},
4770 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
4772 {"version", s_ignore, 0},
4773 {"ABORT", s_abort, 0},
4774 #if defined( TC_M88K ) || defined ( TC_TIC4X )
4775 /* The m88k and tic4x uses sdef instead of def. */
4776 {"sdef", obj_coff_def, 0},
4778 {NULL, NULL, 0} /* end sentinel */
4779 }; /* coff_pseudo_table */
4781 #ifdef BFD_ASSEMBLER
4783 /* Support for a COFF emulation. */
4785 static void coff_pop_insert PARAMS ((void));
4786 static int coff_separate_stab_sections PARAMS ((void));
4791 pop_insert (coff_pseudo_table);
4795 coff_separate_stab_sections ()
4800 const struct format_ops coff_format_ops =
4802 bfd_target_coff_flavour,
4803 0, /* dfl_leading_underscore */
4804 1, /* emit_section_symbols */
4809 0, /* frob_file_before_adjust */
4810 0, /* frob_file_before_fix */
4811 coff_frob_file_after_relocs,
4814 0, /* s_get_align */
4815 0, /* s_set_align */
4816 0, /* s_get_other */
4817 0, /* s_set_other */
4822 0, /* copy_symbol_attributes */
4823 0, /* generate_asm_lineno */
4824 0, /* process_stab */
4825 coff_separate_stab_sections,
4826 obj_coff_init_stab_section,
4827 0, /* sec_sym_ok_for_reloc */
4829 0, /* ecoff_set_ext */
4830 coff_obj_read_begin_hook,
4831 coff_obj_symbol_new_hook