1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-coff.h"
28 /* I think this is probably always correct. */
29 #ifndef KEEP_RELOC_INFO
30 #define KEEP_RELOC_INFO
33 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
34 a new section's attributes when a directive has no valid flags or the
35 "w" flag is used. This default should be appropriate for most. */
36 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
37 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
40 static void obj_coff_bss PARAMS ((int));
41 const char *s_get_name PARAMS ((symbolS * s));
42 static void obj_coff_ln PARAMS ((int));
43 static void obj_coff_def PARAMS ((int));
44 static void obj_coff_endef PARAMS ((int));
45 static void obj_coff_dim PARAMS ((int));
46 static void obj_coff_line PARAMS ((int));
47 static void obj_coff_size PARAMS ((int));
48 static void obj_coff_scl PARAMS ((int));
49 static void obj_coff_tag PARAMS ((int));
50 static void obj_coff_val PARAMS ((int));
51 static void obj_coff_type PARAMS ((int));
52 static void obj_coff_ident PARAMS ((int));
54 static void obj_coff_loc PARAMS((int));
57 /* This is used to hold the symbol built by a sequence of pseudo-ops
58 from .def and .endef. */
59 static symbolS *def_symbol_in_progress;
64 unsigned long chunk_size;
65 unsigned long element_size;
68 unsigned long pointer;
73 stack_init (chunk_size, element_size)
74 unsigned long chunk_size;
75 unsigned long element_size;
79 st = (stack *) malloc (sizeof (stack));
82 st->data = malloc (chunk_size);
89 st->size = chunk_size;
90 st->chunk_size = chunk_size;
91 st->element_size = element_size;
96 /* Not currently used. */
107 stack_push (st, element)
111 if (st->pointer + st->element_size >= st->size)
113 st->size += st->chunk_size;
114 if ((st->data = xrealloc (st->data, st->size)) == (char *) 0)
117 memcpy (st->data + st->pointer, element, st->element_size);
118 st->pointer += st->element_size;
119 return st->data + st->pointer;
126 if (st->pointer < st->element_size)
131 st->pointer -= st->element_size;
132 return st->data + st->pointer;
136 * Maintain a list of the tagnames of the structres.
139 static struct hash_control *tag_hash;
144 tag_hash = hash_new ();
148 tag_insert (name, symbolP)
152 const char *error_string;
154 if ((error_string = hash_jam (tag_hash, name, (char *) symbolP)))
156 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
165 #ifdef STRIP_UNDERSCORE
168 #endif /* STRIP_UNDERSCORE */
169 return (symbolS *) hash_find (tag_hash, name);
173 tag_find_or_make (name)
178 if ((symbolP = tag_find (name)) == NULL)
180 symbolP = symbol_new (name, undefined_section,
181 0, &zero_address_frag);
183 tag_insert (S_GET_NAME (symbolP), symbolP);
185 symbol_table_insert (symbolP);
192 /* We accept the .bss directive to set the section for backward
193 compatibility with earlier versions of gas. */
196 obj_coff_bss (ignore)
197 int ignore ATTRIBUTE_UNUSED;
199 if (*input_line_pointer == '\n')
200 subseg_new (".bss", get_absolute_expression ());
205 /* Handle .weak. This is a GNU extension. */
208 obj_coff_weak (ignore)
209 int ignore ATTRIBUTE_UNUSED;
217 name = input_line_pointer;
218 c = get_symbol_end ();
219 symbolP = symbol_find_or_make (name);
220 *input_line_pointer = c;
224 S_SET_WEAK (symbolP);
228 S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
230 S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT);
235 input_line_pointer++;
237 if (*input_line_pointer == '\n')
243 demand_empty_rest_of_line ();
248 static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *));
250 #define GET_FILENAME_STRING(X) \
251 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
255 fetch_coff_debug_section ()
257 static segT debug_section;
261 s = bfd_make_debug_symbol (stdoutput, (char *) 0, 0);
263 debug_section = s->section;
265 return debug_section;
269 SA_SET_SYM_ENDNDX (sym, val)
273 combined_entry_type *entry, *p;
275 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
276 p = coffsymbol (symbol_get_bfdsym (val))->native;
277 entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p;
282 SA_SET_SYM_TAGNDX (sym, val)
286 combined_entry_type *entry, *p;
288 entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
289 p = coffsymbol (symbol_get_bfdsym (val))->native;
290 entry->u.auxent.x_sym.x_tagndx.p = p;
295 S_GET_DATA_TYPE (sym)
298 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type;
302 S_SET_DATA_TYPE (sym, val)
306 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type = val;
311 S_GET_STORAGE_CLASS (sym)
314 return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass;
318 S_SET_STORAGE_CLASS (sym, val)
322 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass = val;
326 /* Merge a debug symbol containing debug information into a normal symbol. */
329 c_symbol_merge (debug, normal)
333 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
334 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
336 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
338 /* take the most we have */
339 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
342 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
344 /* Move all the auxiliary information. */
345 memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug),
346 (S_GET_NUMBER_AUXILIARY (debug)
347 * sizeof (*SYM_AUXINFO (debug))));
350 /* Move the debug flags. */
351 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
355 c_dot_file_symbol (filename)
356 const char *filename;
360 /* BFD converts filename to a .file symbol with an aux entry. It
361 also handles chaining. */
362 symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag);
364 S_SET_STORAGE_CLASS (symbolP, C_FILE);
365 S_SET_NUMBER_AUXILIARY (symbolP, 1);
367 symbol_get_bfdsym (symbolP)->flags = BSF_DEBUGGING;
374 listing_source_file (filename);
379 /* Make sure that the symbol is first on the symbol chain */
380 if (symbol_rootP != symbolP)
382 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
383 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
384 } /* if not first on the list */
387 /* Line number handling */
390 struct line_no *next;
397 /* Symbol of last function, which we should hang line#s off of. */
398 static symbolS *line_fsym;
400 #define in_function() (line_fsym != 0)
401 #define clear_function() (line_fsym = 0)
402 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
406 coff_obj_symbol_new_hook (symbolP)
409 long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
410 char * s = (char *) xmalloc (sz);
413 coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s;
415 S_SET_DATA_TYPE (symbolP, T_NULL);
416 S_SET_STORAGE_CLASS (symbolP, 0);
417 S_SET_NUMBER_AUXILIARY (symbolP, 0);
419 if (S_IS_STRING (symbolP))
420 SF_SET_STRING (symbolP);
422 if (S_IS_LOCAL (symbolP))
423 SF_SET_LOCAL (symbolP);
428 * Handle .ln directives.
431 static symbolS *current_lineno_sym;
432 static struct line_no *line_nos;
433 /* @@ Blindly assume all .ln directives will be in the .text section... */
437 add_lineno (frag, offset, num)
442 struct line_no *new_line =
443 (struct line_no *) xmalloc (sizeof (struct line_no));
444 if (!current_lineno_sym)
450 /* Zero is used as an end marker in the file. */
451 as_warn (_("Line numbers must be positive integers\n"));
454 new_line->next = line_nos;
455 new_line->frag = frag;
456 new_line->l.line_number = num;
457 new_line->l.u.offset = offset;
463 coff_add_linesym (sym)
468 coffsymbol (symbol_get_bfdsym (current_lineno_sym))->lineno =
473 current_lineno_sym = sym;
477 obj_coff_ln (appline)
482 if (! appline && def_symbol_in_progress != NULL)
484 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
485 demand_empty_rest_of_line ();
489 l = get_absolute_expression ();
492 add_lineno (frag_now, frag_now_fix (), l);
496 new_logical_line ((char *) NULL, l - 1);
505 l += coff_line_base - 1;
506 listing_source_line (l);
511 demand_empty_rest_of_line ();
514 /* .loc is essentially the same as .ln; parse it for assembler
518 obj_coff_loc (ignore)
519 int ignore ATTRIBUTE_UNUSED;
523 /* FIXME: Why do we need this check? We need it for ECOFF, but why
524 do we need it for COFF? */
525 if (now_seg != text_section)
527 as_warn (_(".loc outside of .text"));
528 demand_empty_rest_of_line ();
532 if (def_symbol_in_progress != NULL)
534 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
535 demand_empty_rest_of_line ();
539 /* Skip the file number. */
541 get_absolute_expression ();
544 lineno = get_absolute_expression ();
552 lineno += coff_line_base - 1;
553 listing_source_line (lineno);
558 demand_empty_rest_of_line ();
560 add_lineno (frag_now, frag_now_fix (), lineno);
563 /* Handle the .ident pseudo-op. */
566 obj_coff_ident (ignore)
567 int ignore ATTRIBUTE_UNUSED;
569 segT current_seg = now_seg;
570 subsegT current_subseg = now_subseg;
576 /* We could put it in .comment, but that creates an extra section
577 that shouldn't be loaded into memory, which requires linker
578 changes... For now, until proven otherwise, use .rdata. */
579 sec = subseg_new (".rdata$zzz", 0);
580 bfd_set_section_flags (stdoutput, sec,
581 ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)
582 & bfd_applicable_section_flags (stdoutput)));
585 subseg_new (".comment", 0);
589 subseg_set (current_seg, current_subseg);
595 * Handle .def directives.
597 * One might ask : why can't we symbol_new if the symbol does not
598 * already exist and fill it with debug information. Because of
599 * the C_EFCN special symbol. It would clobber the value of the
600 * function symbol before we have a chance to notice that it is
601 * a C_EFCN. And a second reason is that the code is more clear this
602 * way. (at least I think it is :-).
606 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
607 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
608 *input_line_pointer == '\t') \
609 input_line_pointer++;
613 int what ATTRIBUTE_UNUSED;
615 char name_end; /* Char after the end of name */
616 char *symbol_name; /* Name of the debug symbol */
617 char *symbol_name_copy; /* Temporary copy of the name */
618 unsigned int symbol_name_length;
620 if (def_symbol_in_progress != NULL)
622 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
623 demand_empty_rest_of_line ();
625 } /* if not inside .def/.endef */
629 symbol_name = input_line_pointer;
630 #ifdef STRIP_UNDERSCORE
631 if (symbol_name[0] == '_' && symbol_name[1] != 0)
633 #endif /* STRIP_UNDERSCORE */
635 name_end = get_symbol_end ();
636 symbol_name_length = strlen (symbol_name);
637 symbol_name_copy = xmalloc (symbol_name_length + 1);
638 strcpy (symbol_name_copy, symbol_name);
639 #ifdef tc_canonicalize_symbol_name
640 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
643 /* Initialize the new symbol */
644 def_symbol_in_progress = symbol_make (symbol_name_copy);
645 symbol_set_frag (def_symbol_in_progress, &zero_address_frag);
646 S_SET_VALUE (def_symbol_in_progress, 0);
648 if (S_IS_STRING (def_symbol_in_progress))
649 SF_SET_STRING (def_symbol_in_progress);
651 *input_line_pointer = name_end;
653 demand_empty_rest_of_line ();
656 unsigned int dim_index;
659 obj_coff_endef (ignore)
660 int ignore ATTRIBUTE_UNUSED;
662 symbolS *symbolP = NULL;
664 /* DIM BUG FIX sac@cygnus.com */
666 if (def_symbol_in_progress == NULL)
668 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
669 demand_empty_rest_of_line ();
671 } /* if not inside .def/.endef */
673 /* Set the section number according to storage class. */
674 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
679 SF_SET_TAG (def_symbol_in_progress);
680 /* intentional fallthrough */
683 SF_SET_DEBUG (def_symbol_in_progress);
684 S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());
688 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
689 /* intentional fallthrough */
691 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
692 /* intentional fallthrough */
696 S_SET_SEGMENT (def_symbol_in_progress, text_section);
698 name = S_GET_NAME (def_symbol_in_progress);
699 if (name[0] == '.' && name[2] == 'f' && name[3] == '\0')
705 if (! in_function ())
706 as_warn (_("`%s' symbol without preceding function"), name);
707 /* Will need relocating. */
708 SF_SET_PROCESS (def_symbol_in_progress);
714 /* The MS compilers output the actual endline, not the
715 function-relative one... we want to match without
716 changing the assembler input. */
717 SA_SET_SYM_LNNO (def_symbol_in_progress,
718 (SA_GET_SYM_LNNO (def_symbol_in_progress)
729 #endif /* C_AUTOARG */
735 SF_SET_DEBUG (def_symbol_in_progress);
736 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
743 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
753 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
760 as_warn (_("unexpected storage class %d"),
761 S_GET_STORAGE_CLASS (def_symbol_in_progress));
763 } /* switch on storage class */
765 /* Now that we have built a debug symbol, try to find if we should
766 merge with an existing symbol or not. If a symbol is C_EFCN or
767 absolute_section or untagged SEG_DEBUG it never merges. We also
768 don't merge labels, which are in a different namespace, nor
769 symbols which have not yet been defined since they are typically
770 unique, nor do we merge tags with non-tags. */
772 /* Two cases for functions. Either debug followed by definition or
773 definition followed by debug. For definition first, we will
774 merge the debug symbol into the definition. For debug first, the
775 lineno entry MUST point to the definition function or else it
776 will point off into space when obj_crawl_symbol_chain() merges
777 the debug symbol into the real symbol. Therefor, let's presume
778 the debug symbol is a real function reference. */
780 /* FIXME-SOON If for some reason the definition label/symbol is
781 never seen, this will probably leave an undefined symbol at link
784 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
785 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
786 || (!strcmp (bfd_get_section_name (stdoutput,
787 S_GET_SEGMENT (def_symbol_in_progress)),
789 && !SF_GET_TAG (def_symbol_in_progress))
790 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
791 || ! symbol_constant_p (def_symbol_in_progress)
792 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
793 DO_NOT_STRIP)) == NULL
794 || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))
796 /* If it already is at the end of the symbol list, do nothing */
797 if (def_symbol_in_progress != symbol_lastP)
799 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
800 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
806 /* This symbol already exists, merge the newly created symbol
807 into the old one. This is not mandatory. The linker can
808 handle duplicate symbols correctly. But I guess that it save
809 a *lot* of space if the assembly file defines a lot of
812 /* The debug entry (def_symbol_in_progress) is merged into the
813 previous definition. */
815 c_symbol_merge (def_symbol_in_progress, symbolP);
816 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
818 def_symbol_in_progress = symbolP;
820 if (SF_GET_FUNCTION (def_symbol_in_progress)
821 || SF_GET_TAG (def_symbol_in_progress)
822 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
824 /* For functions, and tags, and static symbols, the symbol
825 *must* be where the debug symbol appears. Move the
826 existing symbol to the current place. */
827 /* If it already is at the end of the symbol list, do nothing */
828 if (def_symbol_in_progress != symbol_lastP)
830 symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
831 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);
836 if (SF_GET_TAG (def_symbol_in_progress))
840 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
842 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
843 tag_insert (S_GET_NAME (def_symbol_in_progress),
844 def_symbol_in_progress);
847 if (SF_GET_FUNCTION (def_symbol_in_progress))
849 know (sizeof (def_symbol_in_progress) <= sizeof (long));
850 set_function (def_symbol_in_progress);
851 SF_SET_PROCESS (def_symbol_in_progress);
855 /* That is, if this is the first time we've seen the
857 symbol_table_insert (def_symbol_in_progress);
858 } /* definition follows debug */
859 } /* Create the line number entry pointing to the function being defined */
861 def_symbol_in_progress = NULL;
862 demand_empty_rest_of_line ();
866 obj_coff_dim (ignore)
867 int ignore ATTRIBUTE_UNUSED;
871 if (def_symbol_in_progress == NULL)
873 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
874 demand_empty_rest_of_line ();
876 } /* if not inside .def/.endef */
878 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
880 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
883 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
884 get_absolute_expression ());
886 switch (*input_line_pointer)
889 input_line_pointer++;
893 as_warn (_("badly formed .dim directive ignored"));
894 /* intentional fallthrough */
902 demand_empty_rest_of_line ();
906 obj_coff_line (ignore)
907 int ignore ATTRIBUTE_UNUSED;
911 if (def_symbol_in_progress == NULL)
913 /* Probably stabs-style line? */
918 this_base = get_absolute_expression ();
919 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress)))
920 coff_line_base = this_base;
922 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
923 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
925 demand_empty_rest_of_line ();
928 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0)
933 listing_source_line ((unsigned int) this_base);
939 obj_coff_size (ignore)
940 int ignore ATTRIBUTE_UNUSED;
942 if (def_symbol_in_progress == NULL)
944 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
945 demand_empty_rest_of_line ();
947 } /* if not inside .def/.endef */
949 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
950 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
951 demand_empty_rest_of_line ();
955 obj_coff_scl (ignore)
956 int ignore ATTRIBUTE_UNUSED;
958 if (def_symbol_in_progress == NULL)
960 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
961 demand_empty_rest_of_line ();
963 } /* if not inside .def/.endef */
965 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
966 demand_empty_rest_of_line ();
970 obj_coff_tag (ignore)
971 int ignore ATTRIBUTE_UNUSED;
976 if (def_symbol_in_progress == NULL)
978 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
979 demand_empty_rest_of_line ();
983 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
984 symbol_name = input_line_pointer;
985 name_end = get_symbol_end ();
987 #ifdef tc_canonicalize_symbol_name
988 symbol_name = tc_canonicalize_symbol_name (symbol_name);
991 /* Assume that the symbol referred to by .tag is always defined.
992 This was a bad assumption. I've added find_or_make. xoxorich. */
993 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
994 tag_find_or_make (symbol_name));
995 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
997 as_warn (_("tag not found for .tag %s"), symbol_name);
1000 SF_SET_TAGGED (def_symbol_in_progress);
1001 *input_line_pointer = name_end;
1003 demand_empty_rest_of_line ();
1007 obj_coff_type (ignore)
1008 int ignore ATTRIBUTE_UNUSED;
1010 if (def_symbol_in_progress == NULL)
1012 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1013 demand_empty_rest_of_line ();
1015 } /* if not inside .def/.endef */
1017 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
1019 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
1020 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
1022 SF_SET_FUNCTION (def_symbol_in_progress);
1023 } /* is a function */
1025 demand_empty_rest_of_line ();
1029 obj_coff_val (ignore)
1030 int ignore ATTRIBUTE_UNUSED;
1032 if (def_symbol_in_progress == NULL)
1034 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1035 demand_empty_rest_of_line ();
1037 } /* if not inside .def/.endef */
1039 if (is_name_beginner (*input_line_pointer))
1041 char *symbol_name = input_line_pointer;
1042 char name_end = get_symbol_end ();
1044 #ifdef tc_canonicalize_symbol_name
1045 symbol_name = tc_canonicalize_symbol_name (symbol_name);
1047 if (!strcmp (symbol_name, "."))
1049 symbol_set_frag (def_symbol_in_progress, frag_now);
1050 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
1051 /* If the .val is != from the .def (e.g. statics) */
1053 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
1057 exp.X_op = O_symbol;
1058 exp.X_add_symbol = symbol_find_or_make (symbol_name);
1059 exp.X_op_symbol = NULL;
1060 exp.X_add_number = 0;
1061 symbol_set_value_expression (def_symbol_in_progress, &exp);
1063 /* If the segment is undefined when the forward reference is
1064 resolved, then copy the segment id from the forward
1066 SF_SET_GET_SEGMENT (def_symbol_in_progress);
1068 /* FIXME: gcc can generate address expressions here in
1069 unusual cases (search for "obscure" in sdbout.c). We
1070 just ignore the offset here, thus generating incorrect
1071 debugging information. We ignore the rest of the line
1074 /* Otherwise, it is the name of a non debug symbol and its value
1075 will be calculated later. */
1076 *input_line_pointer = name_end;
1080 S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
1081 } /* if symbol based */
1083 demand_empty_rest_of_line ();
1087 coff_obj_read_begin_hook ()
1089 /* These had better be the same. Usually 18 bytes. */
1091 know (sizeof (SYMENT) == sizeof (AUXENT));
1092 know (SYMESZ == AUXESZ);
1098 symbolS *coff_last_function;
1099 static symbolS *coff_last_bf;
1102 coff_frob_symbol (symp, punt)
1106 static symbolS *last_tagP;
1107 static stack *block_stack;
1108 static symbolS *set_end;
1109 symbolS *next_set_end = NULL;
1111 if (symp == &abs_symbol)
1117 if (current_lineno_sym)
1118 coff_add_linesym ((symbolS *) 0);
1121 block_stack = stack_init (512, sizeof (symbolS*));
1123 if (S_IS_WEAK (symp))
1126 S_SET_STORAGE_CLASS (symp, C_NT_WEAK);
1128 S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
1132 if (!S_IS_DEFINED (symp)
1133 && !S_IS_WEAK (symp)
1134 && S_GET_STORAGE_CLASS (symp) != C_STAT)
1135 S_SET_STORAGE_CLASS (symp, C_EXT);
1137 if (!SF_GET_DEBUG (symp))
1140 if (!SF_GET_LOCAL (symp)
1141 && !SF_GET_STATICS (symp)
1142 && S_GET_STORAGE_CLASS (symp) != C_LABEL
1143 && symbol_constant_p(symp)
1144 && (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
1147 c_symbol_merge (symp, real);
1150 if (S_GET_STORAGE_CLASS (symp) == C_NULL)
1152 if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp))
1154 assert (S_GET_VALUE (symp) == 0);
1155 S_SET_EXTERNAL (symp);
1157 else if (S_GET_SEGMENT (symp) == text_section
1158 && symp != seg_info (text_section)->sym)
1160 S_SET_STORAGE_CLASS (symp, C_LABEL);
1164 S_SET_STORAGE_CLASS (symp, C_STAT);
1167 if (SF_GET_PROCESS (symp))
1169 if (S_GET_STORAGE_CLASS (symp) == C_BLOCK)
1171 if (!strcmp (S_GET_NAME (symp), ".bb"))
1172 stack_push (block_stack, (char *) &symp);
1176 begin = *(symbolS **) stack_pop (block_stack);
1178 as_warn (_("mismatched .eb"));
1180 next_set_end = begin;
1183 if (coff_last_function == 0 && SF_GET_FUNCTION (symp))
1185 union internal_auxent *auxp;
1186 coff_last_function = symp;
1187 if (S_GET_NUMBER_AUXILIARY (symp) < 1)
1188 S_SET_NUMBER_AUXILIARY (symp, 1);
1189 auxp = SYM_AUXENT (symp);
1190 memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0,
1191 sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen));
1193 if (S_GET_STORAGE_CLASS (symp) == C_EFCN)
1195 if (coff_last_function == 0)
1196 as_fatal (_("C_EFCN symbol out of scope"));
1197 SA_SET_SYM_FSIZE (coff_last_function,
1198 (long) (S_GET_VALUE (symp)
1199 - S_GET_VALUE (coff_last_function)));
1200 next_set_end = coff_last_function;
1201 coff_last_function = 0;
1204 if (S_IS_EXTERNAL (symp))
1205 S_SET_STORAGE_CLASS (symp, C_EXT);
1206 else if (SF_GET_LOCAL (symp))
1209 if (SF_GET_FUNCTION (symp))
1210 symbol_get_bfdsym (symp)->flags |= BSF_FUNCTION;
1215 /* Double check weak symbols. */
1216 if (S_IS_WEAK (symp) && S_IS_COMMON (symp))
1217 as_bad (_("Symbol `%s' can not be both weak and common"),
1220 if (SF_GET_TAG (symp))
1222 else if (S_GET_STORAGE_CLASS (symp) == C_EOS)
1223 next_set_end = last_tagP;
1226 /* This is pretty horrible, but we have to set *punt correctly in
1227 order to call SA_SET_SYM_ENDNDX correctly. */
1228 if (! symbol_used_in_reloc_p (symp)
1229 && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0
1230 || (! S_IS_EXTERNAL (symp)
1231 && ! symbol_get_tc (symp)->output
1232 && S_GET_STORAGE_CLASS (symp) != C_FILE)))
1236 if (set_end != (symbolS *) NULL
1238 && ((symbol_get_bfdsym (symp)->flags & BSF_NOT_AT_END) != 0
1239 || (S_IS_DEFINED (symp)
1240 && ! S_IS_COMMON (symp)
1241 && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp)))))
1243 SA_SET_SYM_ENDNDX (set_end, symp);
1247 if (next_set_end != NULL)
1249 if (set_end != NULL)
1250 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1251 S_GET_NAME (set_end));
1252 set_end = next_set_end;
1256 && S_GET_STORAGE_CLASS (symp) == C_FCN
1257 && strcmp (S_GET_NAME (symp), ".bf") == 0)
1259 if (coff_last_bf != NULL)
1260 SA_SET_SYM_ENDNDX (coff_last_bf, symp);
1261 coff_last_bf = symp;
1264 if (coffsymbol (symbol_get_bfdsym (symp))->lineno)
1267 struct line_no *lptr;
1270 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1271 for (i = 0; lptr; lptr = lptr->next)
1273 lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
1275 /* We need i entries for line numbers, plus 1 for the first
1276 entry which BFD will override, plus 1 for the last zero
1277 entry (a marker for BFD). */
1278 l = (alent *) xmalloc ((i + 2) * sizeof (alent));
1279 coffsymbol (symbol_get_bfdsym (symp))->lineno = l;
1280 l[i + 1].line_number = 0;
1281 l[i + 1].u.sym = NULL;
1285 lptr->l.u.offset += lptr->frag->fr_address / OCTETS_PER_BYTE;
1293 coff_adjust_section_syms (abfd, sec, x)
1294 bfd *abfd ATTRIBUTE_UNUSED;
1296 PTR x ATTRIBUTE_UNUSED;
1299 segment_info_type *seginfo = seg_info (sec);
1300 int nlnno, nrelocs = 0;
1302 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1303 tc-ppc.c. Do not get confused by it. */
1304 if (seginfo == NULL)
1307 if (!strcmp (sec->name, ".text"))
1308 nlnno = coff_n_line_nos;
1312 /* @@ Hope that none of the fixups expand to more than one reloc
1314 fixS *fixp = seginfo->fix_root;
1317 if (! fixp->fx_done)
1319 fixp = fixp->fx_next;
1322 if (bfd_get_section_size_before_reloc (sec) == 0
1325 && sec != text_section
1326 && sec != data_section
1327 && sec != bss_section)
1329 secsym = section_symbol (sec);
1330 /* This is an estimate; we'll plug in the real value using
1331 SET_SECTION_RELOCS later */
1332 SA_SET_SCN_NRELOC (secsym, nrelocs);
1333 SA_SET_SCN_NLINNO (secsym, nlnno);
1337 coff_frob_file_after_relocs ()
1339 bfd_map_over_sections (stdoutput, coff_adjust_section_syms, (char*) 0);
1343 * implement the .section pseudo op:
1344 * .section name {, "flags"}
1346 * | +--- optional flags: 'b' for bss
1348 * +-- section name 'l' for lib
1352 * 'd' (apparently m88k for data)
1354 * 'r' for read-only data
1355 * 's' for shared data (PE)
1356 * But if the argument is not a quoted string, treat it as a
1357 * subsegment number.
1361 obj_coff_section (ignore)
1362 int ignore ATTRIBUTE_UNUSED;
1364 /* Strip out the section name */
1369 flagword flags, oldflags;
1380 section_name = input_line_pointer;
1381 c = get_symbol_end ();
1383 name = xmalloc (input_line_pointer - section_name + 1);
1384 strcpy (name, section_name);
1386 *input_line_pointer = c;
1391 flags = SEC_NO_FLAGS;
1393 if (*input_line_pointer == ',')
1395 ++input_line_pointer;
1397 if (*input_line_pointer != '"')
1398 exp = get_absolute_expression ();
1401 ++input_line_pointer;
1402 while (*input_line_pointer != '"'
1403 && ! is_end_of_line[(unsigned char) *input_line_pointer])
1405 switch (*input_line_pointer)
1407 case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
1408 case 'n': flags &=~ SEC_LOAD; break;
1409 case 'd': flags |= SEC_DATA | SEC_LOAD; /* fall through */
1410 case 'w': flags &=~ SEC_READONLY; break;
1411 case 'x': flags |= SEC_CODE | SEC_LOAD; break;
1412 case 'r': flags |= SEC_READONLY; break;
1413 case 's': flags |= SEC_SHARED; break;
1415 case 'i': /* STYP_INFO */
1416 case 'l': /* STYP_LIB */
1417 case 'o': /* STYP_OVER */
1418 as_warn (_("unsupported section attribute '%c'"),
1419 *input_line_pointer);
1423 as_warn(_("unknown section attribute '%c'"),
1424 *input_line_pointer);
1427 ++input_line_pointer;
1429 if (*input_line_pointer == '"')
1430 ++input_line_pointer;
1434 sec = subseg_new (name, (subsegT) exp);
1436 oldflags = bfd_get_section_flags (stdoutput, sec);
1437 if (oldflags == SEC_NO_FLAGS)
1439 /* Set section flags for a new section just created by subseg_new.
1440 Provide a default if no flags were parsed. */
1441 if (flags == SEC_NO_FLAGS)
1442 flags = TC_COFF_SECTION_DEFAULT_ATTRIBUTES;
1444 #ifdef COFF_LONG_SECTION_NAMES
1445 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1446 sections so adjust_reloc_syms in write.c will correctly handle
1447 relocs which refer to non-local symbols in these sections. */
1448 if (strncmp (name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0)
1449 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
1452 if (! bfd_set_section_flags (stdoutput, sec, flags))
1453 as_warn (_("error setting flags for \"%s\": %s"),
1454 bfd_section_name (stdoutput, sec),
1455 bfd_errmsg (bfd_get_error ()));
1457 else if (flags != SEC_NO_FLAGS)
1459 /* This section's attributes have already been set. Warn if the
1460 attributes don't match. */
1461 flagword matchflags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
1462 | SEC_DATA | SEC_SHARED;
1463 if ((flags ^ oldflags) & matchflags)
1464 as_warn (_("Ignoring changed section attributes for %s"), name);
1467 demand_empty_rest_of_line ();
1471 coff_adjust_symtab ()
1473 if (symbol_rootP == NULL
1474 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
1475 c_dot_file_symbol ("fake");
1479 coff_frob_section (sec)
1485 bfd_vma size, n_entries, mask;
1486 bfd_vma align_power = (bfd_vma)sec->alignment_power + OCTETS_PER_BYTE_POWER;
1488 /* The COFF back end in BFD requires that all section sizes be
1489 rounded up to multiples of the corresponding section alignments,
1490 supposedly because standard COFF has no other way of encoding alignment
1491 for sections. If your COFF flavor has a different way of encoding
1492 section alignment, then skip this step, as TICOFF does. */
1493 size = bfd_get_section_size_before_reloc (sec);
1494 mask = ((bfd_vma) 1 << align_power) - 1;
1495 #if !defined(TICOFF)
1501 new_size = (size + mask) & ~mask;
1502 bfd_set_section_size (stdoutput, sec, new_size);
1504 /* If the size had to be rounded up, add some padding in
1505 the last non-empty frag. */
1506 fragp = seg_info (sec)->frchainP->frch_root;
1507 last = seg_info (sec)->frchainP->frch_last;
1508 while (fragp->fr_next != last)
1509 fragp = fragp->fr_next;
1510 last->fr_address = size;
1511 fragp->fr_offset += new_size - size;
1515 /* If the section size is non-zero, the section symbol needs an aux
1516 entry associated with it, indicating the size. We don't know
1517 all the values yet; coff_frob_symbol will fill them in later. */
1520 || sec == text_section
1521 || sec == data_section
1522 || sec == bss_section)
1525 symbolS *secsym = section_symbol (sec);
1527 S_SET_STORAGE_CLASS (secsym, C_STAT);
1528 S_SET_NUMBER_AUXILIARY (secsym, 1);
1529 SF_SET_STATICS (secsym);
1530 SA_SET_SCN_SCNLEN (secsym, size);
1533 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1534 #ifndef STAB_SECTION_NAME
1535 #define STAB_SECTION_NAME ".stab"
1537 #ifndef STAB_STRING_SECTION_NAME
1538 #define STAB_STRING_SECTION_NAME ".stabstr"
1540 if (strcmp (STAB_STRING_SECTION_NAME, sec->name))
1544 sec = subseg_get (STAB_SECTION_NAME, 0);
1545 /* size is already rounded up, since other section will be listed first */
1546 size = bfd_get_section_size_before_reloc (strsec);
1548 n_entries = bfd_get_section_size_before_reloc (sec) / 12 - 1;
1550 /* Find first non-empty frag. It should be large enough. */
1551 fragp = seg_info (sec)->frchainP->frch_root;
1552 while (fragp && fragp->fr_fix == 0)
1553 fragp = fragp->fr_next;
1554 assert (fragp != 0 && fragp->fr_fix >= 12);
1556 /* Store the values. */
1557 p = fragp->fr_literal;
1558 bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6);
1559 bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8);
1563 obj_coff_init_stab_section (seg)
1569 unsigned int stroff;
1571 /* Make space for this first symbol. */
1575 as_where (&file, (unsigned int *) NULL);
1576 stabstr_name = (char *) alloca (strlen (seg->name) + 4);
1577 strcpy (stabstr_name, seg->name);
1578 strcat (stabstr_name, "str");
1579 stroff = get_stab_string_offset (file, stabstr_name);
1581 md_number_to_chars (p, stroff, 4);
1590 return ((s == NULL) ? "(NULL)" : S_GET_NAME (s));
1598 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
1600 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1601 (unsigned long) symbolP,
1602 S_GET_NAME(symbolP),
1603 (long) S_GET_DATA_TYPE(symbolP),
1604 S_GET_STORAGE_CLASS(symbolP),
1605 (int) S_GET_SEGMENT(symbolP));
1611 #else /* not BFD_ASSEMBLER */
1614 /* This is needed because we include internal bfd things. */
1618 #include "libcoff.h"
1621 #include "coff/pe.h"
1624 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1625 that we can stick sections together without causing trouble. */
1627 #define NOP_OPCODE 0x00
1630 /* The zeroes if symbol name is longer than 8 chars */
1631 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1633 #define MIN(a,b) ((a) < (b)? (a) : (b))
1635 /* This vector is used to turn a gas internal segment number into a
1636 section number suitable for insertion into a coff symbol table.
1637 This must correspond to seg_info_off_by_4. */
1639 const short seg_N_TYPE[] =
1640 { /* in: segT out: N_TYPE bits */
1642 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1643 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1644 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1645 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1646 C_UNDEF_SECTION, /* SEG_UNKNOWN */
1647 C_UNDEF_SECTION, /* SEG_GOOF */
1648 C_UNDEF_SECTION, /* SEG_EXPR */
1649 C_DEBUG_SECTION, /* SEG_DEBUG */
1650 C_NTV_SECTION, /* SEG_NTV */
1651 C_PTV_SECTION, /* SEG_PTV */
1652 C_REGISTER_SECTION, /* SEG_REGISTER */
1655 int function_lineoff = -1; /* Offset in line#s where the last function
1656 started (the odd entry for line #0) */
1658 /* structure used to keep the filenames which
1659 are too long around so that we can stick them
1660 into the string table */
1661 struct filename_list
1664 struct filename_list *next;
1667 static struct filename_list *filename_list_head;
1668 static struct filename_list *filename_list_tail;
1670 static symbolS *last_line_symbol;
1672 /* Add 4 to the real value to get the index and compensate the
1673 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1674 section number into a segment number
1676 static symbolS *previous_file_symbol;
1677 void c_symbol_merge ();
1678 static int line_base;
1680 symbolS *c_section_symbol ();
1683 static void fixup_segment PARAMS ((segment_info_type *segP,
1684 segT this_segment_type));
1687 static void fixup_mdeps PARAMS ((fragS *,
1692 static void fill_section PARAMS ((bfd * abfd,
1697 static int c_line_new PARAMS ((symbolS * symbol, long paddr,
1702 static void w_symbols PARAMS ((bfd * abfd, char *where,
1703 symbolS * symbol_rootP));
1705 static void adjust_stab_section PARAMS ((bfd *abfd, segT seg));
1707 static void obj_coff_lcomm PARAMS ((int));
1708 static void obj_coff_text PARAMS ((int));
1709 static void obj_coff_data PARAMS ((int));
1710 void obj_coff_section PARAMS ((int));
1712 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1714 This array maps a COFF section number into a gas section number.
1715 Because COFF uses negative section numbers, you must add 4 to the
1716 COFF section number when indexing into this array; this is done via
1717 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1720 static const segT seg_info_off_by_4[] =
1727 SEG_E0, SEG_E1, SEG_E2, SEG_E3, SEG_E4,
1728 SEG_E5, SEG_E6, SEG_E7, SEG_E8, SEG_E9,
1729 SEG_E10, SEG_E11, SEG_E12, SEG_E13, SEG_E14,
1730 SEG_E15, SEG_E16, SEG_E17, SEG_E18, SEG_E19,
1731 SEG_E20, SEG_E21, SEG_E22, SEG_E23, SEG_E24,
1732 SEG_E25, SEG_E26, SEG_E27, SEG_E28, SEG_E29,
1733 SEG_E30, SEG_E31, SEG_E32, SEG_E33, SEG_E34,
1734 SEG_E35, SEG_E36, SEG_E37, SEG_E38, SEG_E39,
1747 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1749 static relax_addressT
1750 relax_align (address, alignment)
1751 relax_addressT address;
1754 relax_addressT mask;
1755 relax_addressT new_address;
1757 mask = ~((~0) << alignment);
1758 new_address = (address + mask) & (~mask);
1759 return (new_address - address);
1767 return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum);
1770 /* calculate the size of the frag chain and fill in the section header
1771 to contain all of it, also fill in the addr of the sections */
1773 size_section (abfd, idx)
1774 bfd *abfd ATTRIBUTE_UNUSED;
1778 unsigned int size = 0;
1779 fragS *frag = segment_info[idx].frchainP->frch_root;
1782 size = frag->fr_address;
1783 if (frag->fr_address != size)
1785 fprintf (stderr, _("Out of step\n"));
1786 size = frag->fr_address;
1789 switch (frag->fr_type)
1791 #ifdef TC_COFF_SIZEMACHDEP
1792 case rs_machine_dependent:
1793 size += TC_COFF_SIZEMACHDEP (frag);
1797 assert (frag->fr_symbol == 0);
1800 size += frag->fr_fix;
1801 size += frag->fr_offset * frag->fr_var;
1808 size += frag->fr_fix;
1809 off = relax_align (size, frag->fr_offset);
1810 if (frag->fr_subtype != 0 && off > frag->fr_subtype)
1816 BAD_CASE (frag->fr_type);
1819 frag = frag->fr_next;
1821 segment_info[idx].scnhdr.s_size = size;
1827 count_entries_in_chain (idx)
1830 unsigned int nrelocs;
1833 /* Count the relocations */
1834 fixup_ptr = segment_info[idx].fix_root;
1836 while (fixup_ptr != (fixS *) NULL)
1838 if (fixup_ptr->fx_done == 0 && TC_COUNT_RELOC (fixup_ptr))
1841 if (fixup_ptr->fx_r_type == RELOC_CONSTH)
1850 fixup_ptr = fixup_ptr->fx_next;
1857 static int compare_external_relocs PARAMS ((const PTR, const PTR));
1859 /* AUX's ld expects relocations to be sorted */
1861 compare_external_relocs (x, y)
1865 struct external_reloc *a = (struct external_reloc *) x;
1866 struct external_reloc *b = (struct external_reloc *) y;
1867 bfd_vma aadr = bfd_getb32 (a->r_vaddr);
1868 bfd_vma badr = bfd_getb32 (b->r_vaddr);
1869 return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
1874 /* output all the relocations for a section */
1876 do_relocs_for (abfd, h, file_cursor)
1879 unsigned long *file_cursor;
1881 unsigned int nrelocs;
1883 unsigned long reloc_start = *file_cursor;
1885 for (idx = SEG_E0; idx < SEG_LAST; idx++)
1887 if (segment_info[idx].scnhdr.s_name[0])
1889 struct external_reloc *ext_ptr;
1890 struct external_reloc *external_reloc_vec;
1891 unsigned int external_reloc_size;
1892 unsigned int base = segment_info[idx].scnhdr.s_paddr;
1893 fixS *fix_ptr = segment_info[idx].fix_root;
1894 nrelocs = count_entries_in_chain (idx);
1897 /* Bypass this stuff if no relocs. This also incidentally
1898 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1900 external_reloc_size = nrelocs * RELSZ;
1901 external_reloc_vec =
1902 (struct external_reloc *) malloc (external_reloc_size);
1904 ext_ptr = external_reloc_vec;
1906 /* Fill in the internal coff style reloc struct from the
1907 internal fix list. */
1910 struct internal_reloc intr;
1912 /* Only output some of the relocations */
1913 if (fix_ptr->fx_done == 0 && TC_COUNT_RELOC (fix_ptr))
1915 #ifdef TC_RELOC_MANGLE
1916 TC_RELOC_MANGLE (&segment_info[idx], fix_ptr, &intr,
1921 symbolS *symbol_ptr = fix_ptr->fx_addsy;
1923 intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr);
1925 base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where;
1927 #ifdef TC_KEEP_FX_OFFSET
1928 intr.r_offset = fix_ptr->fx_offset;
1933 while (symbol_ptr->sy_value.X_op == O_symbol
1934 && (! S_IS_DEFINED (symbol_ptr)
1935 || S_IS_COMMON (symbol_ptr)))
1939 /* We must avoid looping, as that can occur
1940 with a badly written program. */
1941 n = symbol_ptr->sy_value.X_add_symbol;
1942 if (n == symbol_ptr)
1947 /* Turn the segment of the symbol into an offset. */
1950 resolve_symbol_value (symbol_ptr, 1);
1951 if (! symbol_ptr->sy_resolved)
1956 if (expr_symbol_where (symbol_ptr, &file, &line))
1957 as_bad_where (file, line,
1958 _("unresolved relocation"));
1960 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1961 S_GET_NAME (symbol_ptr));
1963 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
1966 intr.r_symndx = dot->sy_number;
1970 intr.r_symndx = symbol_ptr->sy_number;
1980 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
1983 #if defined(TC_A29K)
1985 /* The 29k has a special kludge for the high 16 bit
1986 reloc. Two relocations are emited, R_IHIHALF,
1987 and R_IHCONST. The second one doesn't contain a
1988 symbol, but uses the value for offset. */
1990 if (intr.r_type == R_IHIHALF)
1992 /* now emit the second bit */
1993 intr.r_type = R_IHCONST;
1994 intr.r_symndx = fix_ptr->fx_addnumber;
1995 (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr);
2001 fix_ptr = fix_ptr->fx_next;
2005 /* Sort the reloc table */
2006 qsort ((PTR) external_reloc_vec, nrelocs,
2007 sizeof (struct external_reloc), compare_external_relocs);
2010 /* Write out the reloc table */
2011 bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size,
2013 free (external_reloc_vec);
2015 /* Fill in section header info. */
2016 segment_info[idx].scnhdr.s_relptr = *file_cursor;
2017 *file_cursor += external_reloc_size;
2018 segment_info[idx].scnhdr.s_nreloc = nrelocs;
2023 segment_info[idx].scnhdr.s_relptr = 0;
2027 /* Set relocation_size field in file headers */
2028 H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0);
2032 /* run through a frag chain and write out the data to go with it, fill
2033 in the scnhdrs with the info on the file postions
2036 fill_section (abfd, h, file_cursor)
2038 object_headers *h ATTRIBUTE_UNUSED;
2039 unsigned long *file_cursor;
2043 unsigned int paddr = 0;
2045 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
2047 unsigned int offset = 0;
2048 struct internal_scnhdr *s = &(segment_info[i].scnhdr);
2054 fragS *frag = segment_info[i].frchainP->frch_root;
2061 buffer = xmalloc (s->s_size);
2062 s->s_scnptr = *file_cursor;
2064 know (s->s_paddr == paddr);
2066 if (strcmp (s->s_name, ".text") == 0)
2067 s->s_flags |= STYP_TEXT;
2068 else if (strcmp (s->s_name, ".data") == 0)
2069 s->s_flags |= STYP_DATA;
2070 else if (strcmp (s->s_name, ".bss") == 0)
2073 s->s_flags |= STYP_BSS;
2075 /* @@ Should make the i386 and a29k coff targets define
2076 COFF_NOLOAD_PROBLEM, and have only one test here. */
2079 #ifndef COFF_NOLOAD_PROBLEM
2080 /* Apparently the SVR3 linker (and exec syscall) and UDI
2081 mondfe progrem are confused by noload sections. */
2082 s->s_flags |= STYP_NOLOAD;
2087 else if (strcmp (s->s_name, ".lit") == 0)
2088 s->s_flags = STYP_LIT | STYP_TEXT;
2089 else if (strcmp (s->s_name, ".init") == 0)
2090 s->s_flags |= STYP_TEXT;
2091 else if (strcmp (s->s_name, ".fini") == 0)
2092 s->s_flags |= STYP_TEXT;
2093 else if (strncmp (s->s_name, ".comment", 8) == 0)
2094 s->s_flags |= STYP_INFO;
2098 unsigned int fill_size;
2099 switch (frag->fr_type)
2101 case rs_machine_dependent:
2104 memcpy (buffer + frag->fr_address,
2106 (unsigned int) frag->fr_fix);
2107 offset += frag->fr_fix;
2112 assert (frag->fr_symbol == 0);
2119 memcpy (buffer + frag->fr_address,
2121 (unsigned int) frag->fr_fix);
2122 offset += frag->fr_fix;
2125 fill_size = frag->fr_var;
2126 if (fill_size && frag->fr_offset > 0)
2129 unsigned int off = frag->fr_fix;
2130 for (count = frag->fr_offset; count; count--)
2132 if (fill_size + frag->fr_address + off <= s->s_size)
2134 memcpy (buffer + frag->fr_address + off,
2135 frag->fr_literal + frag->fr_fix,
2138 offset += fill_size;
2143 case rs_broken_word:
2148 frag = frag->fr_next;
2153 if (s->s_scnptr != 0)
2155 bfd_write (buffer, s->s_size, 1, abfd);
2156 *file_cursor += s->s_size;
2165 /* Coff file generation & utilities */
2168 coff_header_append (abfd, h)
2175 #ifdef COFF_LONG_SECTION_NAMES
2176 unsigned long string_size = 4;
2179 bfd_seek (abfd, 0, 0);
2181 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2182 H_SET_MAGIC_NUMBER (h, COFF_MAGIC);
2183 H_SET_VERSION_STAMP (h, 0);
2184 H_SET_ENTRY_POINT (h, 0);
2185 H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address);
2186 H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address);
2187 H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr,
2189 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2190 H_SET_SIZEOF_OPTIONAL_HEADER (h, 0);
2191 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2193 i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer);
2195 bfd_write (buffer, i, 1, abfd);
2196 bfd_write (buffero, H_GET_SIZEOF_OPTIONAL_HEADER (h), 1, abfd);
2198 for (i = SEG_E0; i < SEG_LAST; i++)
2200 if (segment_info[i].scnhdr.s_name[0])
2204 #ifdef COFF_LONG_SECTION_NAMES
2205 /* Support long section names as found in PE. This code
2206 must coordinate with that in write_object_file and
2208 if (strlen (segment_info[i].name) > SCNNMLEN)
2210 memset (segment_info[i].scnhdr.s_name, 0, SCNNMLEN);
2211 sprintf (segment_info[i].scnhdr.s_name, "/%lu", string_size);
2212 string_size += strlen (segment_info[i].name) + 1;
2216 size = bfd_coff_swap_scnhdr_out (abfd,
2217 &(segment_info[i].scnhdr),
2220 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2221 bfd_write (buffer, size, 1, abfd);
2228 symbol_to_chars (abfd, where, symbolP)
2233 unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
2237 /* Turn any symbols with register attributes into abs symbols */
2238 if (S_GET_SEGMENT (symbolP) == reg_section)
2240 S_SET_SEGMENT (symbolP, absolute_section);
2242 /* At the same time, relocate all symbols to their output value */
2245 val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr
2246 + S_GET_VALUE (symbolP));
2248 val = S_GET_VALUE (symbolP);
2251 S_SET_VALUE (symbolP, val);
2253 symbolP->sy_symbol.ost_entry.n_value = val;
2255 where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry,
2258 for (i = 0; i < numaux; i++)
2260 where += bfd_coff_swap_aux_out (abfd,
2261 &symbolP->sy_symbol.ost_auxent[i],
2262 S_GET_DATA_TYPE (symbolP),
2263 S_GET_STORAGE_CLASS (symbolP),
2271 coff_obj_symbol_new_hook (symbolP)
2274 char underscore = 0; /* Symbol has leading _ */
2276 /* Effective symbol */
2277 /* Store the pointer in the offset. */
2278 S_SET_ZEROES (symbolP, 0L);
2279 S_SET_DATA_TYPE (symbolP, T_NULL);
2280 S_SET_STORAGE_CLASS (symbolP, 0);
2281 S_SET_NUMBER_AUXILIARY (symbolP, 0);
2282 /* Additional information */
2283 symbolP->sy_symbol.ost_flags = 0;
2284 /* Auxiliary entries */
2285 memset ((char *) &symbolP->sy_symbol.ost_auxent[0], 0, AUXESZ);
2287 if (S_IS_STRING (symbolP))
2288 SF_SET_STRING (symbolP);
2289 if (!underscore && S_IS_LOCAL (symbolP))
2290 SF_SET_LOCAL (symbolP);
2294 * Handle .ln directives.
2298 obj_coff_ln (appline)
2303 if (! appline && def_symbol_in_progress != NULL)
2305 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2306 demand_empty_rest_of_line ();
2308 } /* wrong context */
2310 l = get_absolute_expression ();
2311 c_line_new (0, frag_now_fix (), l, frag_now);
2314 new_logical_line ((char *) NULL, l - 1);
2324 listing_source_line ((unsigned int) l);
2329 demand_empty_rest_of_line ();
2335 * Handle .def directives.
2337 * One might ask : why can't we symbol_new if the symbol does not
2338 * already exist and fill it with debug information. Because of
2339 * the C_EFCN special symbol. It would clobber the value of the
2340 * function symbol before we have a chance to notice that it is
2341 * a C_EFCN. And a second reason is that the code is more clear this
2342 * way. (at least I think it is :-).
2346 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2347 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2348 *input_line_pointer == '\t') \
2349 input_line_pointer++;
2353 int what ATTRIBUTE_UNUSED;
2355 char name_end; /* Char after the end of name */
2356 char *symbol_name; /* Name of the debug symbol */
2357 char *symbol_name_copy; /* Temporary copy of the name */
2358 unsigned int symbol_name_length;
2360 if (def_symbol_in_progress != NULL)
2362 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2363 demand_empty_rest_of_line ();
2365 } /* if not inside .def/.endef */
2367 SKIP_WHITESPACES ();
2369 def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress));
2370 memset (def_symbol_in_progress, 0, sizeof (*def_symbol_in_progress));
2372 symbol_name = input_line_pointer;
2373 name_end = get_symbol_end ();
2374 symbol_name_length = strlen (symbol_name);
2375 symbol_name_copy = xmalloc (symbol_name_length + 1);
2376 strcpy (symbol_name_copy, symbol_name);
2377 #ifdef tc_canonicalize_symbol_name
2378 symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
2381 /* Initialize the new symbol */
2382 #ifdef STRIP_UNDERSCORE
2383 S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_'
2384 ? symbol_name_copy + 1
2385 : symbol_name_copy));
2386 #else /* STRIP_UNDERSCORE */
2387 S_SET_NAME (def_symbol_in_progress, symbol_name_copy);
2388 #endif /* STRIP_UNDERSCORE */
2389 /* free(symbol_name_copy); */
2390 def_symbol_in_progress->sy_name_offset = (unsigned long) ~0;
2391 def_symbol_in_progress->sy_number = ~0;
2392 def_symbol_in_progress->sy_frag = &zero_address_frag;
2393 S_SET_VALUE (def_symbol_in_progress, 0);
2395 if (S_IS_STRING (def_symbol_in_progress))
2396 SF_SET_STRING (def_symbol_in_progress);
2398 *input_line_pointer = name_end;
2400 demand_empty_rest_of_line ();
2403 unsigned int dim_index;
2407 obj_coff_endef (ignore)
2408 int ignore ATTRIBUTE_UNUSED;
2410 symbolS *symbolP = 0;
2411 /* DIM BUG FIX sac@cygnus.com */
2413 if (def_symbol_in_progress == NULL)
2415 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2416 demand_empty_rest_of_line ();
2418 } /* if not inside .def/.endef */
2420 /* Set the section number according to storage class. */
2421 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
2426 SF_SET_TAG (def_symbol_in_progress);
2427 /* intentional fallthrough */
2430 SF_SET_DEBUG (def_symbol_in_progress);
2431 S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG);
2435 SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */
2436 /* intentional fallthrough */
2438 SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */
2439 /* intentional fallthrough */
2441 S_SET_SEGMENT (def_symbol_in_progress, SEG_E0);
2443 if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0)
2445 if (function_lineoff < 0)
2447 fprintf (stderr, _("`.bf' symbol without preceding function\n"));
2448 } /* missing function symbol */
2449 SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff;
2451 SF_SET_PROCESS (last_line_symbol);
2452 SF_SET_ADJ_LNNOPTR (last_line_symbol);
2453 SF_SET_PROCESS (def_symbol_in_progress);
2454 function_lineoff = -1;
2456 /* Value is always set to . */
2457 def_symbol_in_progress->sy_frag = frag_now;
2458 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2463 #endif /* C_AUTOARG */
2473 SF_SET_DEBUG (def_symbol_in_progress);
2474 S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
2484 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2490 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress));
2492 } /* switch on storage class */
2494 /* Now that we have built a debug symbol, try to find if we should
2495 merge with an existing symbol or not. If a symbol is C_EFCN or
2496 absolute_section or untagged SEG_DEBUG it never merges. We also
2497 don't merge labels, which are in a different namespace, nor
2498 symbols which have not yet been defined since they are typically
2499 unique, nor do we merge tags with non-tags. */
2501 /* Two cases for functions. Either debug followed by definition or
2502 definition followed by debug. For definition first, we will
2503 merge the debug symbol into the definition. For debug first, the
2504 lineno entry MUST point to the definition function or else it
2505 will point off into space when crawl_symbols() merges the debug
2506 symbol into the real symbol. Therefor, let's presume the debug
2507 symbol is a real function reference. */
2509 /* FIXME-SOON If for some reason the definition label/symbol is
2510 never seen, this will probably leave an undefined symbol at link
2513 if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
2514 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
2515 || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG
2516 && !SF_GET_TAG (def_symbol_in_progress))
2517 || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
2518 || def_symbol_in_progress->sy_value.X_op != O_constant
2519 || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL
2520 || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP)))
2522 symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
2527 /* This symbol already exists, merge the newly created symbol
2528 into the old one. This is not mandatory. The linker can
2529 handle duplicate symbols correctly. But I guess that it save
2530 a *lot* of space if the assembly file defines a lot of
2533 /* The debug entry (def_symbol_in_progress) is merged into the
2534 previous definition. */
2536 c_symbol_merge (def_symbol_in_progress, symbolP);
2537 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2538 def_symbol_in_progress = symbolP;
2540 if (SF_GET_FUNCTION (def_symbol_in_progress)
2541 || SF_GET_TAG (def_symbol_in_progress)
2542 || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
2544 /* For functions, and tags, and static symbols, the symbol
2545 *must* be where the debug symbol appears. Move the
2546 existing symbol to the current place. */
2547 /* If it already is at the end of the symbol list, do nothing */
2548 if (def_symbol_in_progress != symbol_lastP)
2550 symbol_remove (def_symbol_in_progress, &symbol_rootP,
2552 symbol_append (def_symbol_in_progress, symbol_lastP,
2553 &symbol_rootP, &symbol_lastP);
2554 } /* if not already in place */
2556 } /* normal or mergable */
2558 if (SF_GET_TAG (def_symbol_in_progress))
2562 oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),
2564 if (oldtag == NULL || ! SF_GET_TAG (oldtag))
2565 tag_insert (S_GET_NAME (def_symbol_in_progress),
2566 def_symbol_in_progress);
2569 if (SF_GET_FUNCTION (def_symbol_in_progress))
2571 know (sizeof (def_symbol_in_progress) <= sizeof (long));
2573 = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag);
2575 SF_SET_PROCESS (def_symbol_in_progress);
2577 if (symbolP == NULL)
2579 /* That is, if this is the first time we've seen the
2581 symbol_table_insert (def_symbol_in_progress);
2582 } /* definition follows debug */
2583 } /* Create the line number entry pointing to the function being defined */
2585 def_symbol_in_progress = NULL;
2586 demand_empty_rest_of_line ();
2590 obj_coff_dim (ignore)
2591 int ignore ATTRIBUTE_UNUSED;
2595 if (def_symbol_in_progress == NULL)
2597 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2598 demand_empty_rest_of_line ();
2600 } /* if not inside .def/.endef */
2602 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2604 for (dim_index = 0; dim_index < DIMNUM; dim_index++)
2606 SKIP_WHITESPACES ();
2607 SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,
2608 get_absolute_expression ());
2610 switch (*input_line_pointer)
2613 input_line_pointer++;
2617 as_warn (_("badly formed .dim directive ignored"));
2618 /* intentional fallthrough */
2626 demand_empty_rest_of_line ();
2630 obj_coff_line (ignore)
2631 int ignore ATTRIBUTE_UNUSED;
2636 if (def_symbol_in_progress == NULL)
2642 name = S_GET_NAME (def_symbol_in_progress);
2643 this_base = get_absolute_expression ();
2645 /* Only .bf symbols indicate the use of a new base line number; the
2646 line numbers associated with .ef, .bb, .eb are relative to the
2647 start of the containing function. */
2648 if (!strcmp (".bf", name))
2650 #if 0 /* XXX Can we ever have line numbers going backwards? */
2651 if (this_base > line_base)
2654 line_base = this_base;
2662 listing_source_line ((unsigned int) line_base);
2668 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2669 SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
2671 demand_empty_rest_of_line ();
2675 obj_coff_size (ignore)
2676 int ignore ATTRIBUTE_UNUSED;
2678 if (def_symbol_in_progress == NULL)
2680 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2681 demand_empty_rest_of_line ();
2683 } /* if not inside .def/.endef */
2685 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2686 SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
2687 demand_empty_rest_of_line ();
2691 obj_coff_scl (ignore)
2692 int ignore ATTRIBUTE_UNUSED;
2694 if (def_symbol_in_progress == NULL)
2696 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2697 demand_empty_rest_of_line ();
2699 } /* if not inside .def/.endef */
2701 S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
2702 demand_empty_rest_of_line ();
2706 obj_coff_tag (ignore)
2707 int ignore ATTRIBUTE_UNUSED;
2712 if (def_symbol_in_progress == NULL)
2714 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2715 demand_empty_rest_of_line ();
2719 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
2720 symbol_name = input_line_pointer;
2721 name_end = get_symbol_end ();
2722 #ifdef tc_canonicalize_symbol_name
2723 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2726 /* Assume that the symbol referred to by .tag is always defined.
2727 This was a bad assumption. I've added find_or_make. xoxorich. */
2728 SA_SET_SYM_TAGNDX (def_symbol_in_progress,
2729 (long) tag_find_or_make (symbol_name));
2730 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
2732 as_warn (_("tag not found for .tag %s"), symbol_name);
2735 SF_SET_TAGGED (def_symbol_in_progress);
2736 *input_line_pointer = name_end;
2738 demand_empty_rest_of_line ();
2742 obj_coff_type (ignore)
2743 int ignore ATTRIBUTE_UNUSED;
2745 if (def_symbol_in_progress == NULL)
2747 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2748 demand_empty_rest_of_line ();
2750 } /* if not inside .def/.endef */
2752 S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
2754 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
2755 S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
2757 SF_SET_FUNCTION (def_symbol_in_progress);
2758 } /* is a function */
2760 demand_empty_rest_of_line ();
2764 obj_coff_val (ignore)
2765 int ignore ATTRIBUTE_UNUSED;
2767 if (def_symbol_in_progress == NULL)
2769 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2770 demand_empty_rest_of_line ();
2772 } /* if not inside .def/.endef */
2774 if (is_name_beginner (*input_line_pointer))
2776 char *symbol_name = input_line_pointer;
2777 char name_end = get_symbol_end ();
2779 #ifdef tc_canonicalize_symbol_name
2780 symbol_name = tc_canonicalize_symbol_name (symbol_name);
2783 if (!strcmp (symbol_name, "."))
2785 def_symbol_in_progress->sy_frag = frag_now;
2786 S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
2787 /* If the .val is != from the .def (e.g. statics) */
2789 else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name))
2791 def_symbol_in_progress->sy_value.X_op = O_symbol;
2792 def_symbol_in_progress->sy_value.X_add_symbol =
2793 symbol_find_or_make (symbol_name);
2794 def_symbol_in_progress->sy_value.X_op_symbol = NULL;
2795 def_symbol_in_progress->sy_value.X_add_number = 0;
2797 /* If the segment is undefined when the forward reference is
2798 resolved, then copy the segment id from the forward
2800 SF_SET_GET_SEGMENT (def_symbol_in_progress);
2802 /* FIXME: gcc can generate address expressions here in
2803 unusual cases (search for "obscure" in sdbout.c). We
2804 just ignore the offset here, thus generating incorrect
2805 debugging information. We ignore the rest of the line
2808 /* Otherwise, it is the name of a non debug symbol and
2809 its value will be calculated later. */
2810 *input_line_pointer = name_end;
2812 /* FIXME: this is to avoid an error message in the
2813 FIXME case mentioned just above. */
2814 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2815 ++input_line_pointer;
2819 S_SET_VALUE (def_symbol_in_progress,
2820 (valueT) get_absolute_expression ());
2821 } /* if symbol based */
2823 demand_empty_rest_of_line ();
2828 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2829 read.c, which then calls this object file format specific routine. */
2832 obj_coff_pe_handle_link_once (type)
2833 enum linkonce_type type;
2835 seg_info (now_seg)->scnhdr.s_flags |= IMAGE_SCN_LNK_COMDAT;
2837 /* We store the type in the seg_info structure, and use it to set up
2838 the auxiliary entry for the section symbol in c_section_symbol. */
2839 seg_info (now_seg)->linkonce = type;
2845 coff_obj_read_begin_hook ()
2847 /* These had better be the same. Usually 18 bytes. */
2849 know (sizeof (SYMENT) == sizeof (AUXENT));
2850 know (SYMESZ == AUXESZ);
2855 /* This function runs through the symbol table and puts all the
2856 externals onto another chain */
2858 /* The chain of globals. */
2859 symbolS *symbol_globalP;
2860 symbolS *symbol_global_lastP;
2862 /* The chain of externals */
2863 symbolS *symbol_externP;
2864 symbolS *symbol_extern_lastP;
2867 symbolS *last_functionP;
2868 static symbolS *last_bfP;
2875 unsigned int symbol_number = 0;
2876 unsigned int last_file_symno = 0;
2878 struct filename_list *filename_list_scan = filename_list_head;
2880 for (symbolP = symbol_rootP;
2882 symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP)
2884 if (symbolP->sy_mri_common)
2886 if (S_GET_STORAGE_CLASS (symbolP) == C_EXT
2888 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
2890 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)
2891 as_bad (_("%s: global symbols not supported in common sections"),
2892 S_GET_NAME (symbolP));
2893 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2897 if (!SF_GET_DEBUG (symbolP))
2899 /* Debug symbols do not need all this rubbish */
2900 symbolS *real_symbolP;
2902 /* L* and C_EFCN symbols never merge. */
2903 if (!SF_GET_LOCAL (symbolP)
2904 && !SF_GET_STATICS (symbolP)
2905 && S_GET_STORAGE_CLASS (symbolP) != C_LABEL
2906 && symbolP->sy_value.X_op == O_constant
2907 && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP))
2908 && real_symbolP != symbolP)
2910 /* FIXME-SOON: where do dups come from?
2911 Maybe tag references before definitions? xoxorich. */
2912 /* Move the debug data from the debug symbol to the
2913 real symbol. Do NOT do the oposite (i.e. move from
2914 real symbol to debug symbol and remove real symbol from the
2915 list.) Because some pointers refer to the real symbol
2916 whereas no pointers refer to the debug symbol. */
2917 c_symbol_merge (symbolP, real_symbolP);
2918 /* Replace the current symbol by the real one */
2919 /* The symbols will never be the last or the first
2920 because : 1st symbol is .file and 3 last symbols are
2921 .text, .data, .bss */
2922 symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP);
2923 symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP);
2924 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
2925 symbolP = real_symbolP;
2926 } /* if not local but dup'd */
2928 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_E1))
2930 S_SET_SEGMENT (symbolP, SEG_E0);
2931 } /* push data into text */
2933 resolve_symbol_value (symbolP, 1);
2935 if (S_GET_STORAGE_CLASS (symbolP) == C_NULL)
2937 if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP))
2939 S_SET_EXTERNAL (symbolP);
2941 else if (S_GET_SEGMENT (symbolP) == SEG_E0)
2943 S_SET_STORAGE_CLASS (symbolP, C_LABEL);
2947 S_SET_STORAGE_CLASS (symbolP, C_STAT);
2951 /* Mainly to speed up if not -g */
2952 if (SF_GET_PROCESS (symbolP))
2954 /* Handle the nested blocks auxiliary info. */
2955 if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK)
2957 if (!strcmp (S_GET_NAME (symbolP), ".bb"))
2958 stack_push (block_stack, (char *) &symbolP);
2961 register symbolS *begin_symbolP;
2962 begin_symbolP = *(symbolS **) stack_pop (block_stack);
2963 if (begin_symbolP == (symbolS *) 0)
2964 as_warn (_("mismatched .eb"));
2966 SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2);
2969 /* If we are able to identify the type of a function, and we
2970 are out of a function (last_functionP == 0) then, the
2971 function symbol will be associated with an auxiliary
2973 if (last_functionP == (symbolS *) 0 &&
2974 SF_GET_FUNCTION (symbolP))
2976 last_functionP = symbolP;
2978 if (S_GET_NUMBER_AUXILIARY (symbolP) < 1)
2980 S_SET_NUMBER_AUXILIARY (symbolP, 1);
2981 } /* make it at least 1 */
2983 /* Clobber possible stale .dim information. */
2985 /* Iffed out by steve - this fries the lnnoptr info too */
2986 bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen,
2987 sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen));
2990 if (S_GET_STORAGE_CLASS (symbolP) == C_FCN)
2992 if (strcmp (S_GET_NAME (symbolP), ".bf") == 0)
2994 if (last_bfP != NULL)
2995 SA_SET_SYM_ENDNDX (last_bfP, symbol_number);
2999 else if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN)
3001 /* I don't even know if this is needed for sdb. But
3002 the standard assembler generates it, so... */
3003 if (last_functionP == (symbolS *) 0)
3004 as_fatal (_("C_EFCN symbol out of scope"));
3005 SA_SET_SYM_FSIZE (last_functionP,
3006 (long) (S_GET_VALUE (symbolP) -
3007 S_GET_VALUE (last_functionP)));
3008 SA_SET_SYM_ENDNDX (last_functionP, symbol_number);
3009 last_functionP = (symbolS *) 0;
3013 else if (SF_GET_TAG (symbolP))
3015 /* First descriptor of a structure must point to
3016 the first slot after the structure description. */
3017 last_tagP = symbolP;
3020 else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS)
3022 /* +2 take in account the current symbol */
3023 SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2);
3025 else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE)
3027 /* If the filename was too long to fit in the
3028 auxent, put it in the string table */
3029 if (SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3030 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3032 SA_SET_FILE_FNAME_OFFSET (symbolP, string_byte_count);
3033 string_byte_count += strlen (filename_list_scan->filename) + 1;
3034 filename_list_scan = filename_list_scan->next;
3036 if (S_GET_VALUE (symbolP))
3038 S_SET_VALUE (symbolP, last_file_symno);
3039 last_file_symno = symbol_number;
3040 } /* no one points at the first .file symbol */
3041 } /* if debug or tag or eos or file */
3043 #ifdef tc_frob_coff_symbol
3044 tc_frob_coff_symbol (symbolP);
3047 /* We must put the external symbols apart. The loader
3048 does not bomb if we do not. But the references in
3049 the endndx field for a .bb symbol are not corrected
3050 if an external symbol is removed between .bb and .be.
3051 I.e in the following case :
3052 [20] .bb endndx = 22
3055 ld will move the symbol 21 to the end of the list but
3056 endndx will still be 22 instead of 21. */
3059 if (SF_GET_LOCAL (symbolP))
3061 /* remove C_EFCN and LOCAL (L...) symbols */
3062 /* next pointer remains valid */
3063 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3066 else if (symbolP->sy_value.X_op == O_symbol
3067 && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
3069 /* Skip symbols which were equated to undefined or common
3071 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3073 else if (!S_IS_DEFINED (symbolP)
3074 && !S_IS_DEBUG (symbolP)
3075 && !SF_GET_STATICS (symbolP)
3076 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3078 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3080 || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT))
3082 /* if external, Remove from the list */
3083 symbolS *hold = symbol_previous (symbolP);
3085 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3086 symbol_clear_list_pointers (symbolP);
3087 symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP);
3090 else if (! S_IS_DEBUG (symbolP)
3091 && ! SF_GET_STATICS (symbolP)
3092 && ! SF_GET_FUNCTION (symbolP)
3093 && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
3095 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK
3097 || S_GET_STORAGE_CLASS (symbolP) == C_NT_WEAK))
3099 symbolS *hold = symbol_previous (symbolP);
3101 /* The O'Reilly COFF book says that defined global symbols
3102 come at the end of the symbol table, just before
3103 undefined global symbols. */
3105 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3106 symbol_clear_list_pointers (symbolP);
3107 symbol_append (symbolP, symbol_global_lastP, &symbol_globalP,
3108 &symbol_global_lastP);
3113 if (SF_GET_STRING (symbolP))
3115 symbolP->sy_name_offset = string_byte_count;
3116 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
3120 symbolP->sy_name_offset = 0;
3121 } /* fix "long" names */
3123 symbolP->sy_number = symbol_number;
3124 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3125 } /* if local symbol */
3126 } /* traverse the symbol list */
3127 return symbol_number;
3133 glue_symbols (head, tail)
3137 unsigned int symbol_number = 0;
3139 while (*head != NULL)
3141 symbolS *tmp = *head;
3144 symbol_remove (tmp, head, tail);
3145 symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP);
3148 if (SF_GET_STRING (tmp))
3150 tmp->sy_name_offset = string_byte_count;
3151 string_byte_count += strlen (S_GET_NAME (tmp)) + 1;
3155 tmp->sy_name_offset = 0;
3156 } /* fix "long" names */
3158 tmp->sy_number = symbol_number;
3159 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp);
3160 } /* append the entire extern chain */
3162 return symbol_number;
3168 unsigned int symbol_number = 0;
3171 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
3173 symbolP->sy_number = symbol_number;
3175 if (SF_GET_TAGGED (symbolP))
3179 ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number);
3182 symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP);
3185 return symbol_number;
3189 crawl_symbols (h, abfd)
3191 bfd *abfd ATTRIBUTE_UNUSED;
3195 /* Initialize the stack used to keep track of the matching .bb .be */
3197 block_stack = stack_init (512, sizeof (symbolS *));
3199 /* The symbol list should be ordered according to the following sequence
3202 * . debug entries for functions
3203 * . fake symbols for the sections, including .text .data and .bss
3205 * . undefined symbols
3206 * But this is not mandatory. The only important point is to put the
3207 * undefined symbols at the end of the list.
3210 /* Is there a .file symbol ? If not insert one at the beginning. */
3211 if (symbol_rootP == NULL
3212 || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
3214 c_dot_file_symbol ("fake");
3218 * Build up static symbols for the sections, they are filled in later
3222 for (i = SEG_E0; i < SEG_LAST; i++)
3223 if (segment_info[i].scnhdr.s_name[0])
3224 segment_info[i].dot = c_section_symbol (segment_info[i].name,
3227 /* Take all the externals out and put them into another chain */
3228 H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ());
3229 /* Take the externals and glue them onto the end.*/
3230 H_SET_SYMBOL_TABLE_SIZE (h,
3231 (H_GET_SYMBOL_COUNT (h)
3232 + glue_symbols (&symbol_globalP,
3233 &symbol_global_lastP)
3234 + glue_symbols (&symbol_externP,
3235 &symbol_extern_lastP)));
3237 H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ());
3238 know (symbol_globalP == NULL);
3239 know (symbol_global_lastP == NULL);
3240 know (symbol_externP == NULL);
3241 know (symbol_extern_lastP == NULL);
3245 * Find strings by crawling along symbol table chain.
3253 struct filename_list *filename_list_scan = filename_list_head;
3255 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3256 md_number_to_chars (where, (valueT) string_byte_count, 4);
3259 #ifdef COFF_LONG_SECTION_NAMES
3260 /* Support long section names as found in PE. This code must
3261 coordinate with that in coff_header_append and write_object_file. */
3265 for (i = SEG_E0; i < SEG_LAST; i++)
3267 if (segment_info[i].scnhdr.s_name[0]
3268 && strlen (segment_info[i].name) > SCNNMLEN)
3272 size = strlen (segment_info[i].name) + 1;
3273 memcpy (where, segment_info[i].name, size);
3278 #endif /* COFF_LONG_SECTION_NAMES */
3280 for (symbolP = symbol_rootP;
3282 symbolP = symbol_next (symbolP))
3286 if (SF_GET_STRING (symbolP))
3288 size = strlen (S_GET_NAME (symbolP)) + 1;
3289 memcpy (where, S_GET_NAME (symbolP), size);
3292 if (S_GET_STORAGE_CLASS (symbolP) == C_FILE
3293 && SA_GET_FILE_FNAME_ZEROS (symbolP) == 0
3294 && SA_GET_FILE_FNAME_OFFSET (symbolP) != 0)
3296 size = strlen (filename_list_scan->filename) + 1;
3297 memcpy (where, filename_list_scan->filename, size);
3298 filename_list_scan = filename_list_scan ->next;
3305 do_linenos_for (abfd, h, file_cursor)
3308 unsigned long *file_cursor;
3311 unsigned long start = *file_cursor;
3313 for (idx = SEG_E0; idx < SEG_LAST; idx++)
3315 segment_info_type *s = segment_info + idx;
3318 if (s->scnhdr.s_nlnno != 0)
3320 struct lineno_list *line_ptr;
3322 struct external_lineno *buffer =
3323 (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ);
3325 struct external_lineno *dst = buffer;
3327 /* Run through the table we've built and turn it into its external
3328 form, take this chance to remove duplicates */
3330 for (line_ptr = s->lineno_list_head;
3331 line_ptr != (struct lineno_list *) NULL;
3332 line_ptr = line_ptr->next)
3335 if (line_ptr->line.l_lnno == 0)
3337 /* Turn a pointer to a symbol into the symbols' index */
3338 line_ptr->line.l_addr.l_symndx =
3339 ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number;
3343 line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address;
3347 (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst);
3352 s->scnhdr.s_lnnoptr = *file_cursor;
3354 bfd_write (buffer, 1, s->scnhdr.s_nlnno * LINESZ, abfd);
3357 *file_cursor += s->scnhdr.s_nlnno * LINESZ;
3360 H_SET_LINENO_SIZE (h, *file_cursor - start);
3364 /* Now we run through the list of frag chains in a segment and
3365 make all the subsegment frags appear at the end of the
3366 list, as if the seg 0 was extra long */
3373 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3375 frchainS *head = segment_info[i].frchainP;
3377 fragS *prev_frag = &dummy;
3379 while (head && head->frch_seg == i)
3381 prev_frag->fr_next = head->frch_root;
3382 prev_frag = head->frch_last;
3383 head = head->frch_next;
3385 prev_frag->fr_next = 0;
3389 unsigned long machine;
3392 write_object_file ()
3396 struct frchain *frchain_ptr;
3398 object_headers headers;
3399 unsigned long file_cursor;
3402 abfd = bfd_openw (out_file_name, TARGET_FORMAT);
3407 as_perror (_("FATAL: Can't create %s"), out_file_name);
3408 exit (EXIT_FAILURE);
3410 bfd_set_format (abfd, bfd_object);
3411 bfd_set_arch_mach (abfd, BFD_ARCH, machine);
3413 string_byte_count = 4;
3415 for (frchain_ptr = frchain_root;
3416 frchain_ptr != (struct frchain *) NULL;
3417 frchain_ptr = frchain_ptr->frch_next)
3419 /* Run through all the sub-segments and align them up. Also
3420 close any open frags. We tack a .fill onto the end of the
3421 frag chain so that any .align's size can be worked by looking
3422 at the next frag. */
3424 subseg_set (frchain_ptr->frch_seg, frchain_ptr->frch_subseg);
3426 #ifndef SUB_SEGMENT_ALIGN
3427 #define SUB_SEGMENT_ALIGN(SEG) 1
3430 md_do_align (SUB_SEGMENT_ALIGN (now_seg), (char *) NULL, 0, 0,
3433 frag_align (SUB_SEGMENT_ALIGN (now_seg),
3434 subseg_text_p (now_seg) ? NOP_OPCODE : 0,
3439 frag_wane (frag_now);
3440 frag_now->fr_fix = 0;
3441 know (frag_now->fr_next == NULL);
3448 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3450 relax_segment (segment_info[i].frchainP->frch_root, i);
3453 H_SET_NUMBER_OF_SECTIONS (&headers, 0);
3455 /* Find out how big the sections are, and set the addresses. */
3457 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3461 segment_info[i].scnhdr.s_paddr = addr;
3462 segment_info[i].scnhdr.s_vaddr = addr;
3464 if (segment_info[i].scnhdr.s_name[0])
3466 H_SET_NUMBER_OF_SECTIONS (&headers,
3467 H_GET_NUMBER_OF_SECTIONS (&headers) + 1);
3469 #ifdef COFF_LONG_SECTION_NAMES
3470 /* Support long section names as found in PE. This code
3471 must coordinate with that in coff_header_append and
3476 len = strlen (segment_info[i].name);
3478 string_byte_count += len + 1;
3480 #endif /* COFF_LONG_SECTION_NAMES */
3483 size = size_section (abfd, (unsigned int) i);
3486 /* I think the section alignment is only used on the i960; the
3487 i960 needs it, and it should do no harm on other targets. */
3488 #ifdef ALIGNMENT_IN_S_FLAGS
3489 segment_info[i].scnhdr.s_flags |= (section_alignment[i] & 0xF) << 8;
3491 segment_info[i].scnhdr.s_align = 1 << section_alignment[i];
3495 H_SET_TEXT_SIZE (&headers, size);
3496 else if (i == SEG_E1)
3497 H_SET_DATA_SIZE (&headers, size);
3498 else if (i == SEG_E2)
3499 H_SET_BSS_SIZE (&headers, size);
3502 /* Turn the gas native symbol table shape into a coff symbol table */
3503 crawl_symbols (&headers, abfd);
3505 if (string_byte_count == 4)
3506 string_byte_count = 0;
3508 H_SET_STRING_SIZE (&headers, string_byte_count);
3514 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3516 fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i);
3517 fixup_segment (&segment_info[i], i);
3520 /* Look for ".stab" segments and fill in their initial symbols
3522 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
3524 name = segment_info[i].name;
3527 && strncmp (".stab", name, 5) == 0
3528 && strncmp (".stabstr", name, 8) != 0)
3529 adjust_stab_section (abfd, i);
3532 file_cursor = H_GET_TEXT_FILE_OFFSET (&headers);
3534 bfd_seek (abfd, (file_ptr) file_cursor, 0);
3536 /* Plant the data */
3538 fill_section (abfd, &headers, &file_cursor);
3540 do_relocs_for (abfd, &headers, &file_cursor);
3542 do_linenos_for (abfd, &headers, &file_cursor);
3544 H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC);
3545 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3546 H_SET_TIME_STAMP (&headers, (long)time((time_t *)0));
3548 H_SET_TIME_STAMP (&headers, 0);
3550 #ifdef TC_COFF_SET_MACHINE
3551 TC_COFF_SET_MACHINE (&headers);
3555 #define COFF_FLAGS 0
3558 #ifdef KEEP_RELOC_INFO
3559 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3560 COFF_FLAGS | coff_flags));
3562 H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) |
3563 (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) |
3564 COFF_FLAGS | coff_flags));
3568 unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers);
3569 char *buffer1 = xmalloc (symtable_size + string_byte_count + 1);
3571 H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd));
3572 w_symbols (abfd, buffer1, symbol_rootP);
3573 if (string_byte_count > 0)
3574 w_strings (buffer1 + symtable_size);
3575 bfd_write (buffer1, 1, symtable_size + string_byte_count, abfd);
3579 coff_header_append (abfd, &headers);
3581 /* Recent changes to write need this, but where it should
3582 go is up to Ken.. */
3583 if (bfd_close_all_done (abfd) == false)
3584 as_fatal (_("Can't close %s: %s"), out_file_name,
3585 bfd_errmsg (bfd_get_error ()));
3588 extern bfd *stdoutput;
3595 /* Add a new segment. This is called from subseg_new via the
3596 obj_new_segment macro. */
3599 obj_coff_add_segment (name)
3604 #ifndef COFF_LONG_SECTION_NAMES
3605 char buf[SCNNMLEN + 1];
3607 strncpy (buf, name, SCNNMLEN);
3608 buf[SCNNMLEN] = '\0';
3612 for (i = SEG_E0; i < SEG_LAST && segment_info[i].scnhdr.s_name[0]; i++)
3613 if (strcmp (name, segment_info[i].name) == 0)
3618 as_bad (_("Too many new sections; can't add \"%s\""), name);
3622 /* Add a new section. */
3623 strncpy (segment_info[i].scnhdr.s_name, name,
3624 sizeof (segment_info[i].scnhdr.s_name));
3625 segment_info[i].scnhdr.s_flags = STYP_REG;
3626 segment_info[i].name = xstrdup (name);
3632 * implement the .section pseudo op:
3633 * .section name {, "flags"}
3635 * | +--- optional flags: 'b' for bss
3637 * +-- section name 'l' for lib
3641 * 'd' (apparently m88k for data)
3643 * 'r' for read-only data
3644 * But if the argument is not a quoted string, treat it as a
3645 * subsegment number.
3649 obj_coff_section (ignore)
3650 int ignore ATTRIBUTE_UNUSED;
3652 /* Strip out the section name */
3653 char *section_name, *name;
3666 else if (type == 'D')
3668 segment_info[now_seg].scnhdr.s_flags |= flags;
3673 section_name = input_line_pointer;
3674 c = get_symbol_end ();
3676 name = xmalloc (input_line_pointer - section_name + 1);
3677 strcpy (name, section_name);
3679 *input_line_pointer = c;
3685 if (*input_line_pointer == ',')
3687 ++input_line_pointer;
3690 if (*input_line_pointer != '"')
3691 exp = get_absolute_expression ();
3694 ++input_line_pointer;
3695 while (*input_line_pointer != '"'
3696 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3698 switch (*input_line_pointer)
3700 case 'b': flags |= STYP_BSS; break;
3701 case 'i': flags |= STYP_INFO; break;
3702 case 'l': flags |= STYP_LIB; break;
3703 case 'n': flags |= STYP_NOLOAD; break;
3704 case 'o': flags |= STYP_OVER; break;
3706 case 'w': flags |= STYP_DATA; break;
3707 case 'x': flags |= STYP_TEXT; break;
3708 case 'r': flags |= STYP_LIT; break;
3710 as_warn(_("unknown section attribute '%c'"),
3711 *input_line_pointer);
3714 ++input_line_pointer;
3716 if (*input_line_pointer == '"')
3717 ++input_line_pointer;
3721 subseg_new (name, (subsegT) exp);
3723 segment_info[now_seg].scnhdr.s_flags |= flags;
3725 demand_empty_rest_of_line ();
3730 obj_coff_text (ignore)
3731 int ignore ATTRIBUTE_UNUSED;
3733 subseg_new (".text", get_absolute_expression ());
3738 obj_coff_data (ignore)
3739 int ignore ATTRIBUTE_UNUSED;
3741 if (flag_readonly_data_in_text)
3742 subseg_new (".text", get_absolute_expression () + 1000);
3744 subseg_new (".data", get_absolute_expression ());
3748 obj_coff_ident (ignore)
3749 int ignore ATTRIBUTE_UNUSED;
3751 segT current_seg = now_seg; /* save current seg */
3752 subsegT current_subseg = now_subseg;
3753 subseg_new (".comment", 0); /* .comment seg */
3754 stringer (1); /* read string */
3755 subseg_set (current_seg, current_subseg); /* restore current seg */
3759 c_symbol_merge (debug, normal)
3763 S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
3764 S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
3766 if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
3768 S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
3769 } /* take the most we have */
3771 if (S_GET_NUMBER_AUXILIARY (debug) > 0)
3773 memcpy ((char *) &normal->sy_symbol.ost_auxent[0],
3774 (char *) &debug->sy_symbol.ost_auxent[0],
3775 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug) * AUXESZ));
3776 } /* Move all the auxiliary information */
3778 /* Move the debug flags. */
3779 SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
3780 } /* c_symbol_merge() */
3783 c_line_new (symbol, paddr, line_number, frag)
3789 struct lineno_list *new_line =
3790 (struct lineno_list *) xmalloc (sizeof (struct lineno_list));
3792 segment_info_type *s = segment_info + now_seg;
3793 new_line->line.l_lnno = line_number;
3795 if (line_number == 0)
3797 last_line_symbol = symbol;
3798 new_line->line.l_addr.l_symndx = (long) symbol;
3802 new_line->line.l_addr.l_paddr = paddr;
3805 new_line->frag = (char *) frag;
3806 new_line->next = (struct lineno_list *) NULL;
3809 if (s->lineno_list_head == (struct lineno_list *) NULL)
3811 s->lineno_list_head = new_line;
3815 s->lineno_list_tail->next = new_line;
3817 s->lineno_list_tail = new_line;
3818 return LINESZ * s->scnhdr.s_nlnno++;
3822 c_dot_file_symbol (filename)
3827 symbolP = symbol_new (".file",
3830 &zero_address_frag);
3832 S_SET_STORAGE_CLASS (symbolP, C_FILE);
3833 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3835 if (strlen (filename) > FILNMLEN)
3837 /* Filename is too long to fit into an auxent,
3838 we stick it into the string table instead. We keep
3839 a linked list of the filenames we find so we can emit
3841 struct filename_list *f = ((struct filename_list *)
3842 xmalloc (sizeof (struct filename_list)));
3844 f->filename = filename;
3847 SA_SET_FILE_FNAME_ZEROS (symbolP, 0);
3848 SA_SET_FILE_FNAME_OFFSET (symbolP, 1);
3850 if (filename_list_tail)
3851 filename_list_tail->next = f;
3853 filename_list_head = f;
3854 filename_list_tail = f;
3858 SA_SET_FILE_FNAME (symbolP, filename);
3865 listing_source_file (filename);
3871 SF_SET_DEBUG (symbolP);
3872 S_SET_VALUE (symbolP, (valueT) previous_file_symbol);
3874 previous_file_symbol = symbolP;
3876 /* Make sure that the symbol is first on the symbol chain */
3877 if (symbol_rootP != symbolP)
3879 symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
3880 symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
3882 } /* c_dot_file_symbol() */
3885 * Build a 'section static' symbol.
3889 c_section_symbol (name, idx)
3895 symbolP = symbol_find_base (name, DO_NOT_STRIP);
3896 if (symbolP == NULL)
3897 symbolP = symbol_new (name, idx, 0, &zero_address_frag);
3900 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3901 S_SET_SEGMENT (symbolP, idx);
3902 symbolP->sy_frag = &zero_address_frag;
3905 S_SET_STORAGE_CLASS (symbolP, C_STAT);
3906 S_SET_NUMBER_AUXILIARY (symbolP, 1);
3908 SF_SET_STATICS (symbolP);
3911 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3912 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3913 SF_CLEAR_LOCAL (symbolP);
3916 /* If the .linkonce pseudo-op was used for this section, we must
3917 store the information in the auxiliary entry for the section
3919 if (segment_info[idx].linkonce != LINKONCE_UNSET)
3923 switch (segment_info[idx].linkonce)
3927 case LINKONCE_DISCARD:
3928 type = IMAGE_COMDAT_SELECT_ANY;
3930 case LINKONCE_ONE_ONLY:
3931 type = IMAGE_COMDAT_SELECT_NODUPLICATES;
3933 case LINKONCE_SAME_SIZE:
3934 type = IMAGE_COMDAT_SELECT_SAME_SIZE;
3936 case LINKONCE_SAME_CONTENTS:
3937 type = IMAGE_COMDAT_SELECT_EXACT_MATCH;
3941 SYM_AUXENT (symbolP)->x_scn.x_comdat = type;
3946 } /* c_section_symbol() */
3949 w_symbols (abfd, where, symbol_rootP)
3952 symbolS * symbol_rootP;
3957 /* First fill in those values we have only just worked out */
3958 for (i = SEG_E0; i < SEG_LAST; i++)
3960 symbolP = segment_info[i].dot;
3963 SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size);
3964 SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc);
3965 SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno);
3970 * Emit all symbols left in the symbol chain.
3972 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
3974 /* Used to save the offset of the name. It is used to point
3975 to the string in memory but must be a file offset. */
3976 register char *temp;
3978 /* We can't fix the lnnoptr field in yank_symbols with the other
3979 adjustments, because we have to wait until we know where they
3981 if (SF_GET_ADJ_LNNOPTR (symbolP))
3983 SA_GET_SYM_LNNOPTR (symbolP) +=
3984 segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_lnnoptr;
3987 tc_coff_symbol_emit_hook (symbolP);
3989 temp = S_GET_NAME (symbolP);
3990 if (SF_GET_STRING (symbolP))
3992 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
3993 S_SET_ZEROES (symbolP, 0);
3997 memset (symbolP->sy_symbol.ost_entry.n_name, 0, SYMNMLEN);
3998 strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
4000 where = symbol_to_chars (abfd, where, symbolP);
4001 S_SET_NAME (symbolP, temp);
4007 obj_coff_lcomm (ignore)
4008 int ignore ATTRIBUTE_UNUSED;
4020 name = input_line_pointer;
4022 c = get_symbol_end ();
4023 p = input_line_pointer;
4026 if (*input_line_pointer != ',')
4028 as_bad (_("Expected comma after name"));
4029 ignore_rest_of_line ();
4032 if (*input_line_pointer == '\n')
4034 as_bad (_("Missing size expression"));
4037 input_line_pointer++;
4038 if ((temp = get_absolute_expression ()) < 0)
4040 as_warn (_("lcomm length (%d.) <0! Ignored."), temp);
4041 ignore_rest_of_line ();
4046 symbolP = symbol_find_or_make(name);
4048 if (S_GET_SEGMENT(symbolP) == SEG_UNKNOWN &&
4049 S_GET_VALUE(symbolP) == 0)
4054 segT current_seg = now_seg; /* save current seg */
4055 subsegT current_subseg = now_subseg;
4057 subseg_set (SEG_E2, 1);
4058 symbolP->sy_frag = frag_now;
4059 p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP,
4060 (offsetT) temp, (char *) 0);
4062 subseg_set (current_seg, current_subseg); /* restore current seg */
4063 S_SET_SEGMENT(symbolP, SEG_E2);
4064 S_SET_STORAGE_CLASS(symbolP, C_STAT);
4068 as_bad(_("Symbol %s already defined"), name);
4070 demand_empty_rest_of_line();
4075 fixup_mdeps (frags, h, this_segment)
4080 subseg_change (this_segment, 0);
4083 switch (frags->fr_type)
4089 HANDLE_ALIGN (frags);
4091 frags->fr_type = rs_fill;
4093 ((frags->fr_next->fr_address - frags->fr_address - frags->fr_fix)
4096 case rs_machine_dependent:
4097 md_convert_frag (h, this_segment, frags);
4103 frags = frags->fr_next;
4109 #ifndef TC_FORCE_RELOCATION
4110 #define TC_FORCE_RELOCATION(fix) 0
4114 fixup_segment (segP, this_segment_type)
4115 segment_info_type * segP;
4116 segT this_segment_type;
4118 register fixS * fixP;
4119 register symbolS *add_symbolP;
4120 register symbolS *sub_symbolP;
4123 register char *place;
4124 register long where;
4125 register char pcrel;
4126 register fragS *fragP;
4127 register segT add_symbol_segment = absolute_section;
4129 for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next)
4131 fragP = fixP->fx_frag;
4133 where = fixP->fx_where;
4134 place = fragP->fr_literal + where;
4135 size = fixP->fx_size;
4136 add_symbolP = fixP->fx_addsy;
4137 sub_symbolP = fixP->fx_subsy;
4138 add_number = fixP->fx_offset;
4139 pcrel = fixP->fx_pcrel;
4141 /* We want function-relative stabs to work on systems which
4142 may use a relaxing linker; thus we must handle the sym1-sym2
4143 fixups function-relative stabs generates.
4145 Of course, if you actually enable relaxing in the linker, the
4146 line and block scoping information is going to be incorrect
4147 in some cases. The only way to really fix this is to support
4148 a reloc involving the difference of two symbols. */
4150 && (!sub_symbolP || pcrel))
4154 if (fixP->fx_tcbit && SF_GET_CALLNAME (add_symbolP))
4156 /* Relocation should be done via the associated 'bal' entry
4159 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP)))
4161 as_bad_where (fixP->fx_file, fixP->fx_line,
4162 _("No 'bal' entry point for leafproc %s"),
4163 S_GET_NAME (add_symbolP));
4166 fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
4170 /* Make sure the symbols have been resolved; this may not have
4171 happened if these are expression symbols. */
4172 if (add_symbolP != NULL && ! add_symbolP->sy_resolved)
4173 resolve_symbol_value (add_symbolP, 1);
4175 if (add_symbolP != NULL)
4177 /* If this fixup is against a symbol which has been equated
4178 to another symbol, convert it to the other symbol. */
4179 if (add_symbolP->sy_value.X_op == O_symbol
4180 && (! S_IS_DEFINED (add_symbolP)
4181 || S_IS_COMMON (add_symbolP)))
4183 while (add_symbolP->sy_value.X_op == O_symbol
4184 && (! S_IS_DEFINED (add_symbolP)
4185 || S_IS_COMMON (add_symbolP)))
4189 /* We must avoid looping, as that can occur with a
4190 badly written program. */
4191 n = add_symbolP->sy_value.X_add_symbol;
4192 if (n == add_symbolP)
4194 add_number += add_symbolP->sy_value.X_add_number;
4197 fixP->fx_addsy = add_symbolP;
4198 fixP->fx_offset = add_number;
4202 if (sub_symbolP != NULL && ! sub_symbolP->sy_resolved)
4203 resolve_symbol_value (sub_symbolP, 1);
4205 if (add_symbolP != NULL
4206 && add_symbolP->sy_mri_common)
4208 know (add_symbolP->sy_value.X_op == O_symbol);
4209 add_number += S_GET_VALUE (add_symbolP);
4210 fixP->fx_offset = add_number;
4211 add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol;
4216 add_symbol_segment = S_GET_SEGMENT (add_symbolP);
4217 } /* if there is an addend */
4221 if (add_symbolP == NULL || add_symbol_segment == absolute_section)
4223 if (add_symbolP != NULL)
4225 add_number += S_GET_VALUE (add_symbolP);
4227 fixP->fx_addsy = NULL;
4230 /* It's just -sym. */
4231 if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
4233 add_number -= S_GET_VALUE (sub_symbolP);
4240 as_bad_where (fixP->fx_file, fixP->fx_line,
4241 _("Negative of non-absolute symbol %s"),
4242 S_GET_NAME (sub_symbolP));
4244 add_number -= S_GET_VALUE (sub_symbolP);
4245 } /* not absolute */
4247 /* if sub_symbol is in the same segment that add_symbol
4248 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4250 else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
4251 && SEG_NORMAL (add_symbol_segment))
4253 /* Difference of 2 symbols from same segment. Can't
4254 make difference of 2 undefineds: 'value' means
4255 something different for N_UNDF. */
4257 /* Makes no sense to use the difference of 2 arbitrary symbols
4258 as the target of a call instruction. */
4261 as_bad_where (fixP->fx_file, fixP->fx_line,
4262 _("callj to difference of 2 symbols"));
4264 #endif /* TC_I960 */
4265 add_number += S_GET_VALUE (add_symbolP) -
4266 S_GET_VALUE (sub_symbolP);
4269 if (!TC_FORCE_RELOCATION (fixP))
4271 fixP->fx_addsy = NULL;
4272 fixP->fx_subsy = NULL;
4274 #ifdef TC_M68K /* is this right? */
4282 /* Different segments in subtraction. */
4283 know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
4285 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
4287 add_number -= S_GET_VALUE (sub_symbolP);
4290 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
4291 #if 0 /* Okay for 68k, at least... */
4296 /* Make it pc-relative. */
4297 add_number += (md_pcrel_from (fixP)
4298 - S_GET_VALUE (sub_symbolP));
4307 as_bad_where (fixP->fx_file, fixP->fx_line,
4308 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4309 segment_name (S_GET_SEGMENT (sub_symbolP)),
4310 S_GET_NAME (sub_symbolP),
4311 (long) (fragP->fr_address + where));
4314 } /* if sub_symbolP */
4318 if (add_symbol_segment == this_segment_type && pcrel)
4321 * This fixup was made when the symbol's segment was
4322 * SEG_UNKNOWN, but it is now in the local segment.
4323 * So we know how to do the address without relocation.
4326 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4327 * in which cases it modifies *fixP as appropriate. In the case
4328 * of a 'calls', no further work is required, and *fixP has been
4329 * set up to make the rest of the code below a no-op.
4332 #endif /* TC_I960 */
4334 add_number += S_GET_VALUE (add_symbolP);
4335 add_number -= md_pcrel_from (fixP);
4338 add_number -= segP->scnhdr.s_vaddr;
4339 if defined (TC_I386) || defined (TE_LYNX). I now
4340 think that was an error propagated from the case when
4341 we are going to emit the relocation. If we are not
4342 going to emit the relocation, then we just want to
4343 set add_number to the difference between the symbols.
4344 This is a case that would only arise when there is a
4345 PC relative reference from a section other than .text
4346 to a symbol defined in the same section, and the
4347 reference is not relaxed. Since jump instructions on
4348 the i386 are relaxed, this could only arise with a
4349 call instruction. */
4351 pcrel = 0; /* Lie. Don't want further pcrel processing. */
4352 if (!TC_FORCE_RELOCATION (fixP))
4354 fixP->fx_addsy = NULL;
4360 switch (add_symbol_segment)
4362 case absolute_section:
4364 reloc_callj (fixP); /* See comment about reloc_callj() above*/
4365 #endif /* TC_I960 */
4366 add_number += S_GET_VALUE (add_symbolP);
4369 if (!TC_FORCE_RELOCATION (fixP))
4371 fixP->fx_addsy = NULL;
4378 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4379 /* This really should be handled in the linker, but
4380 backward compatibility forbids. */
4381 add_number += S_GET_VALUE (add_symbolP);
4383 add_number += S_GET_VALUE (add_symbolP) +
4384 segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr;
4390 if ((int) fixP->fx_bit_fixP == 13)
4392 /* This is a COBR instruction. They have only a
4393 * 13-bit displacement and are only to be used
4394 * for local branches: flag as error, don't generate
4397 as_bad_where (fixP->fx_file, fixP->fx_line,
4398 _("can't use COBR format with external label"));
4399 fixP->fx_addsy = NULL;
4403 #endif /* TC_I960 */
4404 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4405 /* 386 COFF uses a peculiar format in which the
4406 value of a common symbol is stored in the .text
4407 segment (I've checked this on SVR3.2 and SCO
4408 3.2.2) Ian Taylor <ian@cygnus.com>. */
4409 /* This is also true for 68k COFF on sysv machines
4410 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4411 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4412 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4413 if (S_IS_COMMON (add_symbolP))
4414 add_number += S_GET_VALUE (add_symbolP);
4419 } /* switch on symbol seg */
4420 } /* if not in local seg */
4421 } /* if there was a + symbol */
4425 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4426 /* This adjustment is not correct on the m88k, for which the
4427 linker does all the computation. */
4428 add_number -= md_pcrel_from (fixP);
4430 if (add_symbolP == 0)
4432 fixP->fx_addsy = &abs_symbol;
4433 } /* if there's an add_symbol */
4434 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4435 /* On the 386 we must adjust by the segment vaddr as well.
4438 I changed the i960 to work this way as well. This is
4439 compatible with the current GNU linker behaviour. I do
4440 not know what other i960 COFF assemblers do. This is not
4441 a common case: normally, only assembler code will contain
4442 a PC relative reloc, and only branches which do not
4443 originate in the .text section will have a non-zero
4446 I changed the m68k to work this way as well. This will
4447 break existing PC relative relocs from sections which do
4448 not start at address 0, but it will make ld -r work.
4449 Ian Taylor, 4 Oct 96. */
4451 add_number -= segP->scnhdr.s_vaddr;
4455 #ifdef MD_APPLY_FIX3
4456 md_apply_fix3 (fixP, (valueT *) &add_number, this_segment_type);
4458 md_apply_fix (fixP, add_number);
4461 if (!fixP->fx_bit_fixP && ! fixP->fx_no_overflow)
4464 /* The m88k uses the offset field of the reloc to get around
4467 && ((add_number & ~0xFF)
4468 || (fixP->fx_signed && (add_number & 0x80)))
4469 && ((add_number & ~0xFF) != (-1 & ~0xFF)
4470 || (add_number & 0x80) == 0))
4472 && ((add_number & ~0xFFFF)
4473 || (fixP->fx_signed && (add_number & 0x8000)))
4474 && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF)
4475 || (add_number & 0x8000) == 0)))
4477 as_bad_where (fixP->fx_file, fixP->fx_line,
4478 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4479 (long) add_number, size,
4480 (unsigned long) (fragP->fr_address + where));
4483 #ifdef WARN_SIGNED_OVERFLOW_WORD
4484 /* Warn if a .word value is too large when treated as a
4485 signed number. We already know it is not too negative.
4486 This is to catch over-large switches generated by gcc on
4488 if (!flag_signed_overflow_ok
4490 && add_number > 0x7fff)
4491 as_bad_where (fixP->fx_file, fixP->fx_line,
4492 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4494 (unsigned long) (fragP->fr_address + where));
4496 } /* not a bit fix */
4497 } /* For each fixS in this segment. */
4498 } /* fixup_segment() */
4502 /* The first entry in a .stab section is special. */
4505 obj_coff_init_stab_section (seg)
4511 unsigned int stroff;
4513 /* Make space for this first symbol. */
4517 as_where (&file, (unsigned int *) NULL);
4518 stabstr_name = (char *) alloca (strlen (segment_info[seg].name) + 4);
4519 strcpy (stabstr_name, segment_info[seg].name);
4520 strcat (stabstr_name, "str");
4521 stroff = get_stab_string_offset (file, stabstr_name);
4523 md_number_to_chars (p, stroff, 4);
4526 /* Fill in the counts in the first entry in a .stab section. */
4529 adjust_stab_section(abfd, seg)
4533 segT stabstrseg = SEG_UNKNOWN;
4534 const char *secname, *name2;
4537 int i, strsz = 0, nsyms;
4538 fragS *frag = segment_info[seg].frchainP->frch_root;
4540 /* Look for the associated string table section. */
4542 secname = segment_info[seg].name;
4543 name = (char *) alloca (strlen (secname) + 4);
4544 strcpy (name, secname);
4545 strcat (name, "str");
4547 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
4549 name2 = segment_info[i].name;
4550 if (name2 != NULL && strncmp(name2, name, 8) == 0)
4557 /* If we found the section, get its size. */
4558 if (stabstrseg != SEG_UNKNOWN)
4559 strsz = size_section (abfd, stabstrseg);
4561 nsyms = size_section (abfd, seg) / 12 - 1;
4563 /* Look for the first frag of sufficient size for the initial stab
4564 symbol, and collect a pointer to it. */
4565 while (frag && frag->fr_fix < 12)
4566 frag = frag->fr_next;
4568 p = frag->fr_literal;
4571 /* Write in the number of stab symbols and the size of the string
4573 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
4574 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
4577 #endif /* not BFD_ASSEMBLER */
4579 const pseudo_typeS coff_pseudo_table[] =
4581 {"def", obj_coff_def, 0},
4582 {"dim", obj_coff_dim, 0},
4583 {"endef", obj_coff_endef, 0},
4584 {"line", obj_coff_line, 0},
4585 {"ln", obj_coff_ln, 0},
4586 #ifdef BFD_ASSEMBLER
4587 {"loc", obj_coff_loc, 0},
4589 {"appline", obj_coff_ln, 1},
4590 {"scl", obj_coff_scl, 0},
4591 {"size", obj_coff_size, 0},
4592 {"tag", obj_coff_tag, 0},
4593 {"type", obj_coff_type, 0},
4594 {"val", obj_coff_val, 0},
4595 {"section", obj_coff_section, 0},
4596 {"sect", obj_coff_section, 0},
4597 /* FIXME: We ignore the MRI short attribute. */
4598 {"section.s", obj_coff_section, 0},
4599 {"sect.s", obj_coff_section, 0},
4600 /* We accept the .bss directive for backward compatibility with
4601 earlier versions of gas. */
4602 {"bss", obj_coff_bss, 0},
4603 {"weak", obj_coff_weak, 0},
4604 {"ident", obj_coff_ident, 0},
4605 #ifndef BFD_ASSEMBLER
4606 {"use", obj_coff_section, 0},
4607 {"text", obj_coff_text, 0},
4608 {"data", obj_coff_data, 0},
4609 {"lcomm", obj_coff_lcomm, 0},
4611 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
4613 {"version", s_ignore, 0},
4614 {"ABORT", s_abort, 0},
4616 /* The m88k uses sdef instead of def. */
4617 {"sdef", obj_coff_def, 0},
4619 {NULL, NULL, 0} /* end sentinel */
4620 }; /* coff_pseudo_table */
4622 #ifdef BFD_ASSEMBLER
4624 /* Support for a COFF emulation. */
4626 static void coff_pop_insert PARAMS ((void));
4627 static int coff_separate_stab_sections PARAMS ((void));
4632 pop_insert (coff_pseudo_table);
4636 coff_separate_stab_sections ()
4641 const struct format_ops coff_format_ops =
4643 bfd_target_coff_flavour,
4644 0, /* dfl_leading_underscore */
4645 1, /* emit_section_symbols */
4650 coff_frob_file_after_relocs,
4653 0, /* s_get_align */
4654 0, /* s_set_align */
4655 0, /* s_get_other */
4656 0, /* s_set_other */
4661 0, /* copy_symbol_attributes */
4662 0, /* generate_asm_lineno */
4663 0, /* process_stab */
4664 coff_separate_stab_sections,
4665 obj_coff_init_stab_section,
4666 0, /* sec_sym_ok_for_reloc */
4668 0, /* ecoff_set_ext */
4669 coff_obj_read_begin_hook,
4670 coff_obj_symbol_new_hook